• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unble to write the data into file

 
Narsi Ranch
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

i am developing one sample spring web application that is for write the data into test.dat file when i click Register Button.

I wrote the below code for that. But the problem is , data is not writing into file . I thought , that is some configuration problem.

I placed that file in classes folder and WEB-INF folder. So please help me to resolve that problem.



In handle method of RegisterController class::
---------------------------------------------------------


File file = new File("/test.dat");
System.out.println(file.getPath());
try {
fos = new FileOutputStream(file);
FileWriter fw = new FileWriter(file);
fw.write("hello");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the exception that you get?

Also, based on the Servlet Spec, I don't believe you can write to a file in the WEB-INF directory. I am not positive though.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic