简体   繁体   中英

Array of file scanners

I'm working on condensing my code. Right now, I've created 6 file scanners that each read from a separate file (questions1.txt, questions2.txt...). I've attempted to instead use an array of file scanners like so:

Scanner[] file = new Scanner[6];

for(int i = 0; i > file.length; i++) {
    file[i] = new Scanner(new File("questions" + i+1 + ".txt"));
}

However, when I try to add the first line from a file to a string, it comes back as null:

inLine = file[0].nextLine();

Is what I am attempting possible, or does my code have to be revised?

Your for loop never gets executed, because

for(int i = 0; i > file.length; i++)

should be

for(int i = 0; i < file.length; i++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM