1 PackageCom.xia;2 ImportJava.io.*;3 Public classTest2 {4 5 Public Static voidMain (string[] args) {6 7 //output Stream8 9 Try {TenFileOutputStream fos =NewFileOutputStream ("D:\\213.txt",true);//true to allow append writes One AString str = "\ n Good afternoon!" The weather is very good! ";//\ n "Escape character" - -String str2 = "\ n a good mood"; the -Fos.write (Str.getbytes ());//Overwrite Write - - fos.close (); + -FileInputStream FIS =NewFileInputStream ("D:\\213.txt"); + A byte[] B =New byte[2048]; at - inti =Fis.read (b); - -String str1 =NewString (b, 0, i); - -SYSTEM.OUT.PRINTLN ("Read content =" +str1); in - fis.close (); to +}Catch(Exception e) { - the e.printstacktrace (); * } $ Panax Notoginseng - } the +}
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 ("Read content =" + str1);
Fis.close ();
1 PackageCom.xia;2 3 ImportJava.io.*;4 5 Public classTest3 {6 7 Public Static voidMain (string[] args) {8 9 Try {Ten OneFileReader FR =NewFileReader ("D:\\213.txt"); A - Char[] c=New Char[2048]; - the inti =Fr.read (c); - -String str =NewString (c,0, i); - +SYSTEM.OUT.PRINTLN ("Read content =" +str); - + fr.close (); A at //Write - -FileWriter FW =NewFileWriter ("D:\\213.txt",true); - -Fw.write ("\ n New Additions"); - in fw.close (); - to}Catch(Exception e) { + - e.printstacktrace (); the } * } $}
File creation in Java