发布网友 发布时间:2022-04-25 14:47
共1个回答
热心网友 时间:2023-10-09 20:32
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class TestForOne { public static void main(String[] args) { String s=GetFiles("d:\\111.txt","",1); WriteFiles(s); } public static String GetFiles(String BasePath,String Content, int f) { /* * 读写文件操作 */ String s, s2 = new String(); try { if (f == 1) { BufferedReader in = new BufferedReader(new FileReader(BasePath)); while ((s = in.readLine()) != null) { s2 += s + "\n"; } in.close(); } if(f==2) { PrintWriter out1=new PrintWriter(new BufferedWriter(new FileWriter(BasePath))); out1.println(Content); out1.close(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }