PackageA.ab;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classAC {ints = 0; Public Static voidMain (string[] args) {FileOutputStream fos=NULL; Try{fos=NewFileOutputStream ("D:\\dd\\ff.txt"); } Catch(filenotfoundexception E2) {//TODO auto-generated Catch blockE2.printstacktrace (); } Try{fos.write ("Ddsfs, the high speed of the east, and the low V is VSDF". GetBytes ()); } Catch(IOException E1) {e1.printstacktrace (); } Try { if(Fos! =NULL) {fos.close (); } } Catch(IOException e) {e.printstacktrace (); } Try{FileInputStream fis=NewFileInputStream ("D:\\dd\\ff.txt"); byte[] by =New byte[1024]; intb = 0; Try { while((b = fis.read (by))! =-1) {System.out.println (NewString (by, 0, b)); } } Catch(IOException e) {e.printstacktrace (); } finally { if(FIS! =NULL) { Try{fis.close (); } Catch(IOException e) {e.printstacktrace (); } } } } Catch(FileNotFoundException e) {e.printstacktrace (); } }}
View Code
Examples of FileOutputStream and FileInputStream use in Java