java - How to insert text read strings into specific variables -
i having issues inserting each line of simple textfile specific variable want go to. example text file ordered (no spaces in text file between strings editor put them together)
dallas
78 f
north, 15 mph
dallasimage
denver
29 f
south, 10 mph
denverimage
and want dallas in city variable, 78f in temperature variable, , on until text ends, @ moment goes city variable, prints there! know scanner has next line never used before got stuck here.
import java.io.bufferedreader; import java.io.file; import java.io.filereader; import java.io.ioexception; public class textreader { public static void main(string[] args) { try { string city ="a"; string temp ="b"; string wind ="c"; string image = "d"; file file = new file("load.txt"); filereader filereader = new filereader(file); bufferedreader bufferedreader = new bufferedreader(filereader); stringbuffer stringbuffer = new stringbuffer(); string line; while ((line = bufferedreader.readline()) != null) { city = stringbuffer.append(line).tostring(); stringbuffer.append("\n"); //city = line.tostring(); temp = stringbuffer.append(line).tostring(); wind = line; image = line; //stringbuffer.append(line); //stringbuffer.append("\n"); } filereader.close(); system.out.println("contents of file:"); system.out.println(city); system.out.println(temp); //system.out.println(stringbuffer.tostring()); } catch (ioexception e) { e.printstacktrace(); } } }
you have call bufferedreader.readline()
retrieve next line.
while ((line = bufferedreader.readline()) != null) { city = line; temp = bufferedreader.readline(); wind = bufferedreader.readline(); image = bufferedreader.readline(); }
Comments
Post a Comment