publicstaticvoidmain(String[] args){ try { File a =new File("D:/file1.txt"); File b= new File("D:/file3.txt"); FileInputStream c = new FileInputStream(a); FileOutputStream d = new FileOutputStream(b); int e; while((e= c.read())!= -1 ){ d.write(e); } c.close(); d.close(); }catch(FileNotFoundException e) { System.out.println("FileStreamsTest:" + e); }catch(IOException e){ System.err.println("FileStreamTest:" + e); } } }
Writing document data in a byte stream of
try{ File f = new File("C:\Users\Administrator\Desktop\1.txt"); FileOutputStream f1 = new FileOutputStream(f); byte [] a ={}; f1.write(a); f1.close(); } catch(IOException e){ e.printStackTrace(); }
First create a document object, and destinations. Then create objects out of a document, the two linked, then speak
Create and delete documents
File f1 = new File("D:\1.txt"); File f2 = new File("D:\","2.txt"); File f3 = new File("D:\",File.separator+"1.txt"); f2.createNewFile(); f3.delete();
copy and paste
the try { File f1 = new new File ( "D: \ 3.txt" ); File F2 = new new File ( "5.txt" ); FileInputStream in = new new FileInputStream (f1); // create an input stream, from a disk write memory a FileOutputStream OUT = new new a FileOutputStream (F2); // create an output stream, from a disk memory write int C; the while (! (C = in.read ()) = - . 1 ) { out.write (C); } in.close (); the out.close (); } the catch (IOException E) { e.printStackTrace (); }
Read character information
try{ FileReader file = new FileReader("D:\3.txt"); int data = 0; while((data= file.read())!=-1){ System.out.print((char)data); } file.close(); }catch(IOException e){ e.printStackTrace(); }