My current problem is that I would like to write to and read from a file, however, I keep trying to throw exceptions and instantiating my variables only to keep getting errors about how the variables I've declared 'could not have been instantiated.' I'm unsure how to fix this problem.
I've tried using PrintWriter and FileWriter, briefly tried BufferedWriter and other solutions to no avail. I do not know what else I can try.
{ public SettingsHandler() { File configFile=new File(this.getClass().getResource("file").getFile()); try{ file = new Scanner(configFile); }catch (FileNotFoundException e){ System.out.println("Config.ini not found"); } } public void saveSetting(String setting, String value) { FileWriter fw; try{ fw = new FileWriter("myfile.txt", true); }catch (IOException e){ } BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw); } } Every time I try creating the PrintWriter, it gives me an error for the bw parameter: "variable fw might not have been initialized."
Does anyone know how to solve this issue?
null.If the IDE (compiler?) finds a path were the variable is not set, it will complain. In your case the catch block.tryblock.saveSetting