我對此很新穎,這可能是一個非常明顯的答案。在我的csv腳本中,我試圖弄清楚如何使用CSVReader類讀取一個csv文件並寫入一個新的csv文件。該錯誤告訴我writeNext(java.lang.String [])不能應用於(java.lang.String)。我試過使用直接賦值和getString()方法,但沒有任何工作。有任何想法嗎?Java:將String []數組元素賦值給一個String?
我有以下代碼: 修訂
public static void main(String[] args) throws IOException {
//read csv file
CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE));
//write to csv file
CSVWriter writer2 = new CSVWriter(new FileWriter("output.csv"), '\t');
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
String[] newRow = new String[] {nextLine[0],nextLine[2], nextLine[1]};
}
//writer2.writeNext(entries);
writer2.writeAll(newRow);
writer2.close();
}
錯誤: C:\ java的\例子\ ETHImport.java:46:找不到個符號 符號:可變NEWROW 位置:類ETHImport writer2.writeAll(newRow);
1 error
在此先感謝。
我累了,懶惰,不在乎爲你做所有事情:錯誤發生在哪裏? – Pesto 2009-05-27 20:01:37
在你的新代碼中,你只是缺少「新」。它應該是「字符串[] newRow =新的字符串[] ...」 – 2009-05-27 20:58:02
很酷..真的有幫助..不知道爲什麼我得到一個在while循環中聲明的變量 – phill 2009-05-27 21:05:06