//这帖子放了很久了,怎么还能在提问区看到啊...给你写个完整的吧!
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
public class Day01_ReadTxt {
public static void main(String[] args) {
File file=new File("K:\\Test\\TestTxt.txt");//路径
if(file.canExecute())//如果存在就继续;
init(file);
}
private static void init(File file) {
System.gc();
BufferedReader br=null;
try {
br=new BufferedReader(new InputStreamReader(new FileInputStream(file),"GBK"));
for(String str=br.readLine();str!=null;str=br.readLine()) {
str=str.replaceAll("[{}]+", "\r\n");//正则替换;
System.out.print(str);//输出控制台
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(br!=null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
