JAVA的文件创建

 package com.xia;
import java.io.*;
public class test2 { public static void main(String[] args) { //输出流 try {
FileOutputStream fos = new FileOutputStream("d:\\213.txt",true); //true 允许追加写入 String str = "\n大家下午好!天气很不错!"; // \n "转义字符" String str2 = "\n心情不错"; fos.write(str.getBytes()); //覆盖写入 fos.close(); FileInputStream fis = new FileInputStream("d:\\213.txt"); byte[] b = new byte[2048]; int i = fis.read(b); String str1 = new String(b, 0 ,i); System.out.println("读取内容 = "+ str1); fis.close(); } catch (Exception e) { e.printStackTrace();
} } }

FileOutputStream fos = new FileOutputStream("d:\\213.txt",true);

fos.write(str.getBytes());

byte[] b = new byte[2048];

int i = fis.read(b);

String str1 = new String(b, 0 ,i);

System.out.println("读取内容 = "+ str1);

fis.close();

 package com.xia;

 import java.io.*;

 public class test3 {

     public static void main(String[] args) {

         try {

             FileReader fr = new FileReader("d:\\213.txt");

             char[] c= new char[2048];

             int i = fr.read(c);

             String str = new String (c,0,i);

             System.out.println("读取内容 = " + str);

             fr.close();

         //写入

             FileWriter fw = new FileWriter("d:\\213.txt", true);

             fw.write("\n新追加的内容");

             fw.close();

         } catch (Exception e) {

             e.printStackTrace();
}
}
}

JAVA的文件创建

上一篇:多线程09-Lock和Condition


下一篇:LInux系统及其文件系统