Using java in android studio I am trying to read a .txt file and parse it to obtain some data.
the file: https://www.ndbc.noaa.gov/data/latest_obs/latest_obs.txt
I am using he following code to parse the data:
String[] splited = str.trim().replaceAll(" +", " ").split(" ");
String sDate1= splited[3] + "/" + splited[4] + "/" + splited[5]
+ "/" + splited[6] + "/" + splited[7];
try{
java.util.Date date1 = new
java.text.SimpleDateFormat("yyyy/MM/dd/hh/mm").parse(sDate1);
System.out.println(date1);
}
catch(Exception e){
System.out.println(e.getMessage());
}
String windSpeed = splited[9];
String waveHeight = splited[11];
String airTemperature = splited[17];
String waterTemperature = splited[18];
System.out.println(windSpeed);
System.out.println(waveHeight);
System.out.println(airTemperature);
System.out.println(waterTemperature);
if(windSpeed.toLowerCase().equals("mm")){
// write your code here
}
if(waveHeight.toLowerCase().equals("mm")){
// write your code here
}
if(airTemperature.toLowerCase().equals("mm")){
// write your code here
}
if(waterTemperature.toLowerCase().equals("mm")){
// write your code here
}
The '//write your code here' will just return 'data N/A' since mm refers to missing data.
My problem is I am unsure how to open the file from the url to be read. I would like to open the file every hour, and parse the data below so i can assign it to their buoys in my application.