[問題] 如何分辨檔案有換行呀!?
原始碼如下:
package com.example.leo.p2p;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class TransferFile {
public static void main(String[] args) {
File file1 = new File("c:\\from.txt");
File file2 = new File("c:\\to.txt");
try {
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
String s = br.readLine();
while (s != null) {
bw.write(s);
s = br.readLine();
}
bw.flush();
bw.close();
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
請問我讀出來的檔案內容怎麼都不會換行呀,原始檔案內容是有換行的呦!?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.100.51
→
08/18 16:16, , 1F
08/18 16:16, 1F
→
08/18 16:19, , 2F
08/18 16:19, 2F
→
08/18 16:27, , 3F
08/18 16:27, 3F
→
08/19 06:12, , 4F
08/19 06:12, 4F