我的输出没有问题 我得到的输出看起来像这样 01:08.0 02:07.6 03:07.1 04:07.1 05:07.4 06:07.2 07:07.6 08:07.1 09:07.1 10:07.2 当我点击on 给了我相应的时间。输出实际上应该看起来像这样 1:8.035156,2:7.619141,3:7.105469,4:7.072266 只有当我在 append 语句的末尾添加“,”字符时才会发生错误的输出。
public class GeneCsv {
public static void main(String[]args) throws IOException{
File file = new File("file.csv");
FileWriter writer = new FileWriter("/Users/home/fileExpression.csv");
PrintWriter pw = new PrintWriter(writer);
Scanner in = new Scanner(file);
boolean firstLine = true;
String[] temp = null;
while(in.hasNextLine()){
if(firstLine== true){
pw.println(in.nextLine());
firstLine= false;
continue;
}
else{
String line = in.nextLine();
temp = line.split(",");
for(int i =0; i < temp.length ; i++){
pw.append(i + ":" + temp[i] + ",");
}
pw.append("\n");
}
}
pw.flush();
pw.close();
writer.close();
}
}