1 文件的读入与写进
import java.io.*; public class Main{ public static void main(String args []) { try { File inFile = new File("D://example.txt"); BufferedReader bf=new BufferedReader(new FileReader(inFile)); String c; String []temp=new String[100]; int cnt=0; while ((c = bf.readLine())!=null) { temp[cnt]=c; cnt++; } bf.close(); BufferedWriter bw=new BufferedWriter(new FileWriter(inFile)); for(int i=cnt-1;i>=0;i--) { bw.write(temp[i]); bw.newLine(); } bw.flush(); bw.close(); }catch (FileNotFoundException e) { System.out.println("FileStreamsTest: "+e); }catch(IOException e){//(5) System.out.println("FileStreamsTest: "+e); } } }
标签:文件,cnt,java,String,bf,bw,new,程序设计 From: https://www.cnblogs.com/liliczw2209/p/17458883.html