【问题】
I have a .txt called readings, it has the following data in it:
-10,3NW,15cm,4:38
5,15SW,8mm,2:8
8,8ENE,2mm,:25
-5,0,7cm,1
-3,0,3mm
Where the first position represents the Temperature, speed, precipitation and time(hours and minutes)
I want to split the string with tokens = line.split(":");
only if the fourth token exists. My code for splitting the string without doing any splits with the delimiter :
is:
try {
input = new BufferedReader(new FileReader("readings.txt"));
line = input.readLine();
while (line != null ) {
tokens = line.split(",");
temperature = Integer.parseInt(tokens[0].trim());
tokens[1] = tokens[1].trim();
separation = firstNonNumericPosition(tokens[1]);
if (separation == 0 || (separation < 0 && Int