【发布时间】:2015-02-12 10:57:03
【问题描述】:
你能帮我从文本文件的每一行中拆分制表符分隔的单词吗?
例如文件包含以下数据:
26317273105 77016080517 2015-02-11 04:33:37 2015-02-11 04:33:39 2015-02-11 04:39:00
26317273123 77715354350 2015-02-11 04:33:37 2015-02-11 04:33:39 2015-02-11 04:33:00
26317273125 77715354350 2015-02-11 04:33:37 2015-02-11 04:33:42 2015-02-11 04:33:00
26317273127 77715354350 2015-02-11 04:33:37 2015-02-11 04:33:43 2015-02-11 04:33:00
我需要将这些值转换为不同的变量。例如 number=26317273105、phone=77016080517、date1=2015-02-11 04:33:37 等
请帮忙。
编辑:这是我尝试的:
public static void GetLines() {
try {
File fileDir = new File("c:\\download\\tmpfile.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(fileDir), "windows-1251"));
String str;
while ((str = in.readLine()) != null) {
String[] array = str.split("\t");
System.out.println(array[0]);
System.out.println(array[1]);
System.out.println(array[2]);
System.out.println(array[3]);
System.out.println(array[4]);
}
in.close();
}
catch (UnsupportedEncodingException e)
{
System.out.println(e.getMessage());
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
但在输出中我只有第一行的值。
26317273105
77016080517
2015-02-11 04:33:37
2015-02-11 04:33:39
2015-02-11 04:39:00
【问题讨论】:
-
请编辑您的帖子并添加一些您目前尝试过的源代码。
-
@SebastianStigler 添加了我尝试过的内容。但我只有第一行的输出值