• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

unble to write the data into file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic