javaio输出txt文件内容

import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.OutputStream;
import java.io.FileOutputStream;
public class TestDemo{


    public static void main(String[] args) throws Exception{//直接抛出,实际开发必须进行处理
        File file=new File("D:"+File.separator+"desktop"+File.separator+"MyCodes"+File.separator+"mldn.txt");
        //如果文件目录不存在需要先创建文件目录
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();

        }

        OutputStream output= new FileOutputStream(file);
        //字节输出流需要使用byte类型,需要将String类对象转换为字节数组
        String str="Persist is still in my heart,so don not lose confident to me!";
        byte data[]=str.getBytes();

        int a=data.length;
        output.write(data,0,a);
        System.out.println(a);
        output.close();
    }

}

猜你喜欢

转载自blog.csdn.net/guohaocan/article/details/80931607