Friday, September 20, 2019

string - Check what data type the next line of a file is in java without moving the current scanner position

I have a input txt file as follows:



int int String String
int int String
int int String
int int String String
int int String
...



There will always be 2 ints followed by either 1 or 2 strings. The problem is, I don't know when there will be 2 strings or when there will be 1.



How would I check if there is a 2nd string after the 1st string (and if so, scan it into the variable string2, and I will append string2 to the end of string1 after)



The solution I thought of is something along the lines of



after String1 is scanned:
if nextline == String, then scan it into string2, start scanning loop over
if nextline != String, start scanning loop over



But I don't know how to code this in java

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...