标签:多线程 get adl phi void out 文件路径 有一个 print
1 import java.io.*; 2 3 public class FileIO_StringBuffer { 4 public static void main(String[] args) { 5 //读文件到Stringbuffer 6 StringBuffer sb = new StringBuffer(); 7 String sourcePath = "C:\\Users\\Administrator\\Desktop\\1.txt";//源文件路径(*.*) 8 BufferedReader br = null; 9 try { 10 br = new BufferedReader(new FileReader(sourcePath)); 11 String str; 12 while((str = br.readLine()) != null) {//逐行读取 13 sb.append(str);//加在StringBuffer尾 14 sb.append("\r\n");//行尾 加换行符 15 } 16 br.close();//别忘记,切记 17 } 18 catch(Exception e){ 19 System.out.println(e.getMessage()); 20 } 21 22 //写入文件 23 String targetPath = "C:\\Users\\Administrator\\Desktop\\2.txt";//目标文件路径 24 File f = new File(targetPath);//新建文件 25 try { 26 BufferedWriter bw = new BufferedWriter(new FileWriter(f)); 27 bw.write(sb.toString()); 28 bw.flush(); 29 bw.close(); 30 } 31 catch(Exception e) { 32 System.out.println(e.getMessage()); 33 } 34 } 35 }
欢迎留言讨论!
标签:多线程 get adl phi void out 文件路径 有一个 print
原文地址:https://www.cnblogs.com/yocichen/p/9307469.html