0
寫入記事本我的文字像在一個記事本該讀取和Java中
文本記事本的字符串:
date amount intrest tenure debitamount name address state city zipcode phone altphone mailid refaddress ref refphoneno emptype employment
12/11/1987 12345 3.5 144 32456 durga f rao 456 under road
dallas dl 2435 2222-22-2222 2222-22-2222 [email protected]
165 nala road raj 22-22-22-2222 it 12
15/05/1986 2345 6.4 144 45789 rama k nand 789 residensy
newyork ny 2222-22-2222 2222-22-2222 [email protected]
189 ring road hen 22-22-22-22-2222 it 12
16/12/1985 1234 6.5 144 35265 rama j rao 123 dura residensy meknoor
mn 2222-22-2222 2222-22-2222 [email protected] 891 cing road vinky
22-22-22-2222 it 12
12/11/1987 12345 3.5 144 32456 durga f rao 456 under road dallas dl
2435 2222-22-2222 2222-22-2222 [email protected] 165 nala road raj
22-22-22-2222 it 12
out put should be like below
in between name and address single space and all other double space
12/11/1987 12345 3.5 144 32456 durga f rao 456 under road
dallas dl 2435 2222-22-2222 2222-22-2222 [email protected]
165 nala road raj 22-22-22-2222 it 12
15/05/1986 2345 6.4 144 45789 rama k nand 789 residensy
newyork ny 2222-22-2222 2222-22-2222 [email protected]
189 ring road hen 22-22-22-22-2222 it 12
16/12/1985 1234 6.5 144 35265 rama j rao 123 dura residensy meknoor
mn 2222-22-2222 2222-22-2222 [email protected] 891 cing road vinky
22-22-22-2222 it 12
12/11/1987 12345 3.5 144 32456 dura f rao 456 under road dallas dl
2435 2222-22-2222 2222-22-2222 [email protected] 165 nala road raj
22-22-22-2222 it 12
我想我的輸出應該像下面 在這兩者之間單名空間和所有其他雙空間的名稱和地址?
我寫了下面的代碼,但我沒能得到期望的輸出中
可以在任何一個可以幫助我?我試圖
代碼:
public static String newLine = System.getProperty("line.separator");
public static void main(String args[]){
FileWriter iWrite=null;
try {
iWrite = new FileWriter("C:/Documents and Settings/pavan/My Documents/output.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
List<String> lines = FileUtils.readLines(new File("C:/Documents and Settings/pavan/My Documents/input.txt"));
for(String lines1:lines){
iWrite.write(lines1);
iWrite.write(newLine);
}
iWrite.close();
} catch (IOException e) {
e.printStackTrace();
}
}
考慮使用'PrintWriter'而不是'FileWriter'。 – 2013-02-11 05:15:30
請提供您的問題的完整信息,不要在SO之外發布鏈接,而是發佈程序的預期輸出和實際輸出。另外,也許你需要在你的'iWrite.write'語句中使用['String#format'](http://goo.gl/SauwK)。 – 2013-02-11 05:16:56
除非有可用的輸入格式說明,否則讀取字段時會出現空格問題。 – 2013-02-11 05:37:17