[英]How to access values of a line, while reading in a text file in Java
I am trying to load in two files at the same time but also access the first gps1 file. 我试图同时加载两个文件,但也访问第一个gps1文件。 I want to access the gps1 file line-by-line and depending on the sentence type which I will explain later I want to do different stuff with that line and then move to the next line.
我想逐行访问gps1文件,并根据稍后将要解释的句子类型,我要对该行进行其他操作,然后移至下一行。
Basically gps1 for example has multiple lines but each line falls under a couple of catagories all starting with $GPS(then other characters). 例如,基本上gps1有多行,但每行都属于几个目录,均以$ GPS(然后是其他字符)开头。 Some of these types have a time stamp which I need to collect and some types do not have a time stamp.
这些类型中的一些具有我需要收集的时间戳,而某些类型没有时间戳。
File gps1File = new File(gpsFile1);
File gps2File = new File(gpsFile2);
FileReader filegps1 = new FileReader(gpsFile1);
FileReader filegps2 = new FileReader(gpsFile2);
BufferedReader buffer1 = new BufferedReader(filegps1);
BufferedReader buffer2 = new BufferedReader(filegps2);
String gps1;
String gps2;
while ((gps1 = buffer1.readLine()) != null) {
The gps1 data file is as follows gps1数据文件如下
$GPGSA,A,3,28,09,26,15,08,05,21,24,07,,,,1.6,1.0,1.3*3A
$GPRMC,151018.000,A,5225.9627,N,00401.1624,W,0.11,104.71,210214,,*14
$GPGGA,151019.000,5225.9627,N,00401.1624,W,1,09,1.0,38.9,M,51.1,M,,0000*72
$GPGSA,A,3,28,09,26,15,08,05,21,24,07,,,,1.6,1.0,1.3*3A
Thanks 谢谢
I don't really understand the problem you are facing but anyway, if you want to get your lines content you can use a StringTokenizer 我不太了解您面临的问题,但是无论如何,如果您想获取行内容,可以使用StringTokenizer
StringTokenizer st = new StringTokenizer(gps1, ","); StringTokenizer st =新的StringTokenizer(gps1,“,”);
And then access the data one by one 然后一个接一个地访问数据
while(st.hasMoreToken) String s = st.nextToken(); while(st.hasMoreToken)字符串s = st.nextToken();
EDIT: NB: the first token will be your "$GPXXX" attribute 编辑:注意:第一个令牌将是您的“ $ GPXXX”属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.