My scanner wont close when i have multiple assignments to it.. With this code i get resource leak on the [second in = new Scanner(textfile);]
However if i a new scanner it works. Is there any way? maybe possible to make the scanner go to first line again, so that i dont have to assign the scanner textfile to it again?
public static String[][] lesFil(Scanner input) {
Scanner in;
String fileName = "d";
try {
in = new Scanner(textfile);
while (in.hasNextLine()) {
in.nextLine();
}
in = new Scanner(textfile);
while (in.hasNextLine()) {
in.nextLine();
}
in.close();
}
catch (FileNotFoundException e) {
}
return null;
}
EDIT: First while loop counts the number of lines in the textfile (To set an array size), then the second while stores the data of the file in a string array.