I am trying to return the value of the method but the loop is throwing an error because the return has to be in the method body not in the loop. I am using system.out.println and it is works but I want to use return instead.
package AnimeAid;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ReadFile {
public void getFileInformation() throws IOException {
try{
String file;
file = "tra.srt";
Charset charset = Charset.defaultCharset();
Path path = Paths.get(file);
BufferedReader reader = Files.newBufferedReader(path, charset);
System.out.printf("Lines from %s:%n",file);
String line;
while((line = reader.readLine()) != null) {
if (line.indexOf(':') != -1 && line.indexOf(',') != -1 && line.indexOf('0') != -1) {
System.out.println(line.substring(0, 12));
}
}
}catch(FileNotFoundException ex){
System.err.println(ex);
}
}
}
void.