I'm trying to write a class that handles reading files. In order to read the file word by word, I used the following code which I found on the internet. Netbeans seems to disagree and says that it cannot find the symbole br inside the while loop.
public class Reader {
public String file2string() {
String line;
try (InputStream fis = new FileInputStream("smth")) {
InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
BufferedReader br = new BufferedReader(isr);
} catch (IOException ex) {
Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
}
{
while ((line = br.readLine()) != null) {
String[] words = line.split(" ");
// Now you have a String array containing each word in the current line
}
}
return line;
}
}