我在下面的文本文件中有大约50行数据,其中包含以下内容
Date= 1/1/2012 (dd:mm:yyyy) Time= 1:44:10 (hh:mm:ss)
Recording Started at 1:44:10 (hh:mm:ss)
X-Value = -0.525108, Y-Value = 7.746691, Z-Value = 5.863008, Timestamp(milliseconds) = 23001
X-Value = -0.755030, Y-Value = 7.861651, Z-Value = 6.016289, Timestamp(milliseconds) = 23208
X-Value = -0.448467, Y-Value = 8.551417, Z-Value = 4.943320, Timestamp(milliseconds) = 23401
Recording Stopped at 1:44:11 (hh:mm:ss)
我现在使用的代码使用BufferedReader读取文件的每一行,但我真正想要做的是从每一行中提取Y值,Z值和时间戳(毫秒)值,然后将其存储在某些行中那种数据结构?这样做的最佳方式是什么?
答案 0 :(得分:0)
将String.split()与comma and white-spae
一起用作分隔符,然后将结果数组元素与=
分开作为分隔符。然后,将结果数组元素添加到ArrayList。
String str = "X-Value = -0.525108, Y-Value = 7.746691, Z-Value = 5.863008, Timestamp(milliseconds) = 23001
";
String[] data_array = str.split(", ");
ArrayList<String> Y_Value = new ArrayList<String>();
Y_Value.add(data_array[1].split("= ")[1]);
答案 1 :(得分:0)