• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

save a file, in a different subdirectory

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I run a servlet that creates a xml file. I use:
response.setContentType("text/plain");
ServletOutputStream outputStream = response.getOutputStream();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outputStream));
to write to the file. But I need to specify a different sub-directory. How can I do that? Everything works but the file gets generated under tomcat\bin and it should be somewhere else.
Thanks,
Francois
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait, I don't understand something. You get the output stream from servlet response and want to write to a file? This stream writes binary data in response, which means it goes to the client who made the request, like web browser.
If You want to write to a file, You should create FileOutputStream, or better FileWriter, with given path and file name.
 
Francois Bourgault
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maciej,
I'll change the code to use what you suggested. I'm new to I/O, how should I specify the path if the new file will be created in WEB-INF/classes, it's the current subdirectory where the servlet is executed.
Thanks,
Francois
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try -
File f = new File("./webapps/examples/WEB-INF/classes/mytestfile.txt");
//whatever filename
FileWriter fw = new FileWriter(f);
fw.write("test");
fw.close();

Hope this is useful...
[ February 15, 2002: Message edited by: Les Dsouza ]
 
Francois Bourgault
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all I will give it a try
Francois.
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic