0

I am trying to load in two files at the same time but also access the first gps1 file. 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.

Basically gps1 for example has multiple lines but each line falls under a couple of catagories all starting with $GPS(then other characters). 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

$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

NJD
  • 197
  • 1
  • 4
  • 17
  • you have not mentionned anything about your second file and how it is linked to your first file. On your first file, simply read it line by line, then use regular expressions or simply String.split to extract the information it has. – XSen Mar 12 '14 at 16:34
  • gps2 is the same as gps1 but it is just a different gps receiving so the data may be slightly out of sync – NJD Mar 12 '14 at 21:58

1 Answers1

0

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 st = new StringTokenizer(gps1, ",");

And then access the data one by one

while(st.hasMoreToken) String s = st.nextToken();

EDIT: NB: the first token will be your "$GPXXX" attribute

Kraiss
  • 919
  • 7
  • 22
  • 1
    I had this: StringTokenizer st = new StringTokenizer(gps1, ","); while(st.hasMoreTokens()) s = st.nextToken(); AND it just printed out storage addresses. I have not used string tokenizer before System.out.println(st); – NJD Mar 12 '14 at 22:02
  • nop st.nextToken() return the next token, you should print what is returned. As instance, String s = st.nextToken(); System.out.println(s); The StringTokenizer just help you parse your lines in several tokens. – Kraiss Mar 13 '14 at 13:20