Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help reading in this txt file into structure arrays. I have an idea on how

ID: 653576 • Letter: N

Question

need help reading in this txt file into structure arrays. I have an idea on how to do this however there are more fields then the ones I actually need and don't know how to exclude those fields. Im also not sure if the getline() with the ',' delimited will work to get rid of the commas will I read in the fields.

The file looks like this

834,,,,,,,,,,,,,,,, latitude,longitude,altitude(feet),ascent(feet),speed(mph),distance(feet),max_altitude(feet),max_ascent(feet),max_speed(mph),max_distance(feet),time(millisecond),gps,power,pitch,roll,yaw,motor on

43.5803481,-116.7406331,0,0,0,0,0,0,0,0,539,10,97,178,180,141,0 43.5803481,-116.7406329,0,0,0,0,0,0,0,0,841,10,97,178,180,141,0 43.5803482,-116.7406328,0,0,0,0,0,0,0,0,1125,10,97,178,180,141,0 43.5803481,-116.7406329,-1,0,0,0,0,0,0,0,1420,10,97,178,180,141,0 43.580348,-116.7406328,0,0,0,0,0,0,0,0,1720,10,97,178,180,140,0 43.5803479,-116.7406326,-1,0,0,0,0,0,0,0,2023,10,97,178,180,140,0 43.5803478,-116.7406326,0,0,0,0,0,0,0,0,2344,10,97,178,180,140,0 43.5803476,-116.7406329,-1,0,0,0,0,0,0,0,2620,10,97,178,180,140,0 43.5803475,-116.7406329,-1,0,0,0,0,0,0,0,2922,10,97,178,180,140,0 43.5803473,-116.7406329,0,0,0,0,0,0,0,0,3221,10,97,178,180,140,0 43.5803472,-116.7406329,0,0,0,0,0,0,0,0,3519,10,97,178,180,140,0 43.5803471,-116.740633,0,0,0,0,0,0,0,0,3843,10,97,178,180,140,0

From the file I only need these 10 fields

latitude

longitude

altitude(feet)

speed(mph)

gps

power

pitch

roll

yaw

motor on

This is the first time I am reading in a file with commas and into a struc with arrays so I have no previous experience with that. Before I have been reading in files with only spaces

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileReader;

public class Main {
public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("give full path of your file"));


    String line = null;

    while ((line = br.readLine()) != null) {
      String[] values = line.split(",");
      for (String str : values) {
        System.out.println(str);
      }
    }
    br.close();
}
}