我收到奇怪的输出,当我扫描一个csv文件分裂为“,”,其中每行的长度我追加第i个元素与i +“:”到printwriter.My原始输入看起来像这样。奇怪的输出与Csv文件对应的时间
8.035156 7.619141 7.105469
7.234375 7.8125 8.244141
6.615234 8.224609 6.361328
它们确实被分隔 “”。
输出应该是这个样子
1:8.035156,2:7.619141,3:7.105469,4:7.072266
再次它应该由分隔 “”。
但相反,输出看起来像这样,甚至更奇怪,当我点击选择它给我的时间。当我在附加声明的末尾添加,
字符
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
12:04:06 AM
的输出错误只发生。
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();
}
}
向我们展示至少一些输入文件。 – QuantumMechanic
欢迎来到SO。发布代码时,请尝试格式化以提高可读性。这样做会让更多的人阅读它。我已经为你重新格式化了...这一次。 –
这是我原来的输入8.035156 \t 7.619141 \t 7.105469 \t 7.072266这是我希望我的输出看起来像1:8.035156 \t 2:7.619141 \t 3:7.105469 \t 4:7.072266 Unforunately这是我收到01:08.0 \t 02:07.6 \t 03:07.1 04:07.1我不明白我的输出是如何远程接近这个。顺便说一句,我使用ms excel。 - –