Java_io_PrintWriter和BufferedReader
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java_io_PrintWriter和BufferedReader相关的知识,希望对你有一定的参考价值。
package stream;
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.PrintWriter;
public class TestReader {
public static void main(String[] args) {
BufferedReader br=null;
PrintWriter out=null;
try {
br=new BufferedReader(new FileReader("D:\\JAVA SE\\temp\\main.txt"));
out =new PrintWriter(new BufferedWriter(new FileWriter("D:\\JAVA SE\\temp\\main的new.txt")),true);
String str=null;
while((str=br.readLine())!=null){
out.println(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(br!=null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
if(out!=null) out.close();
}
}
}
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.PrintWriter;
public class TestReader {
public static void main(String[] args) {
BufferedReader br=null;
PrintWriter out=null;
try {
br=new BufferedReader(new FileReader("D:\\JAVA SE\\temp\\main.txt"));
out =new PrintWriter(new BufferedWriter(new FileWriter("D:\\JAVA SE\\temp\\main的new.txt")),true);
String str=null;
while((str=br.readLine())!=null){
out.println(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(br!=null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
if(out!=null) out.close();
}
}
}
以上是关于Java_io_PrintWriter和BufferedReader的主要内容,如果未能解决你的问题,请参考以下文章