generates null (read a word from file)

rstfgbct

New Member
I'm trying to read a word from a file and display it in the console. Although the file contains text, the result is always \[code\]null\[/code\]. What might be the error in the code?Here is the code:\[code\]public class ParsingStrings{private Scanner sc;private static String input;public void openFile(){try{ sc = new Scanner(new File ("E:\\Dropbox\\File.txt")); input = sc.next();}catch(FileNotFoundException e){ e.printStackTrace(); }}public static void main(String[] args) { System.out.println(input); }}\[/code\]
 
Back
Top