po - No need to check this! skip -
so i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute isso i'm trying struggling execute single line in text f
import java.util.scanner; import java.io.*; public class hello { public static void main(string[] args) throws ioexception { scanner keyboard = new scanner(system.in); system.out.print(); string response = keyboard.nextline(); file infile = new file(response); scanner route = new scanner(infile); while () { system.out.print("); string word = keyboard.next(); string street = route.next(); string stopnum = route.next();
you closing file after read 1 "line" (actually, i'm not sure how many lines you're reading - don't call nextline
). aren't parsing line. also, i'd prefer try-with-resources
on explicit close (and many of variables class names). finally, need check if line
matches criteria. might done like,
scanner keyboard = new scanner(system.in); system.out.print("enter filename >> "); string response = keyboard.nextline(); file infile = new file(response); system.out.print("enter tram tracker id >> "); string word = keyboard.nextline(); // <-- read line. bad idea leave trailing // new lines. try (scanner route = new scanner(infile)) { while (route.hasnextline()) { string[] line = route.nextline().split("\\^"); string street = line[0]; string stopnum = line[1]; string trkid = line[2]; string road = line[3]; string suburb = line[4]; if (!trkid.equals(word)) { continue; } system.out.printf("street: %s, stop: %s, id: %s, road: %s, suburb: %s%n", street, stopnum, trkid, road, suburb); } }
Comments
Post a Comment