Question

When i debug the code below it throws a FileNotFoundException on line properties.store(fos, "none"), any specific reason for it?

EDIT: By Stack Trace you mean the following then here it is:

Exception(Throwable).<init>() line: 249 [local variables unavailable]   
Exception.<init>() line: not available  
Thread.getStackTrace() line: not available  
JCP.WriteVariablesHashmap(HashMap<String,Object>) line: 51  
JCP.NewMethod(String[]) line: 133   
JCP.InteractiveMode(String[]) line: 165 
JCP.BatchOrInterActive(String[]) line: 96   
Main.main(String[]) line: 13    

Code:

public void WriteVariablesHashmap(HashMap<String, Object> hashMap){
    try {
        File file=new File("Variables.ser");
        FileOutputStream fos = null;

        Properties properties = new Properties();
        fos=new FileOutputStream(file);

        for (Map.Entry<String,Object> entry : hashMap.entrySet()) {
            properties.put(entry.getKey(), entry.getValue());
        }
        System.out.println(file);

        properties.store(fos, "none");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
Was it helpful?

Solution

Stacktrace would be helpful. Also, can you confirm if you have read-write permission in your user directory or if any file called Variables.ser exists. From Javadocs 1.6,

if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top