(一)
String readPath = "";
String writePath = "";
BufferedReader in = null;
BufferedWriter os = null;
try {
// 读取文件(readPaht)内容
if(null != in){
in.close();
}
in = new BufferedReader(new InputStreamReader(new FileInputStream(readPath)));
//
if(null != os){
os.close();
}
os = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writePath)));
String line = in.readLine();
while (null != line && !"".equals(line)) {
os.write(line);
os.newLine();
line = in.readLine();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try{
if(null != in){
in.close();
}
if(null != os){
os.close();
}
}catch (Exception e) {
e.printStackTrace();
}
}
(二)
BufferedReader in = new BufferedReader(new FileReader("D://bug.txt"));
String line = null;
List<String> list = new ArrayList<String>();
while((line = in.readLine())!=null)
{
//System.out.println(line);
list.add(line);
}
for(String temp: list){
System.out.println(temp);
}