Friday 20 September 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...