• 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

Using fileoutputstream in a servlet

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From my servlet, i am not able to make a file using fileoutput stream.I want to make the file outside web-inf.Is it not possible?
 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us what you are trying with?
That would be easier to answer!

Thank you.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void copyDirectory(File srcDir, File dstDir) throws IOException {

String[] children = srcDir.list();
for (int i=0; i<children.length; i++) {
copyFile(new File(srcDir, children[i]),
new File(dstDir, children[i]));

}

}

void copyFile(File src, File dst) throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(src));
OutputStream out = new BufferedOutputStream( new FileOutputStream(dst));

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}

Above code is working fine in simple java file,but not in servlet.

OutputStream out = new BufferedOutputStream( new FileOutputStream(dst)); : At this line,control gets hanged and not going further.

If i write same code in JSP, file is getting created successfully, but it is created in OC4J/bin directory.
We are using OC4J application server.

From servlet, i want to create file at location from where it is accessible by jsp.
Please let me know, how can we do that.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raj Kumar Bindal:
If i write same code in JSP, file is getting created successfully, but it is created in OC4J/bin directory.
We are using OC4J application server.

From servlet, i want to create file at location from where it is accessible by jsp.

If you want to create a file in a specific directory, then specify the full path to that directory. If you use a relative path, then it's relative to your server's current working directory. That probably isn't a useful place for your files to be stored. (I didn't read your code so I don't know what kind of path you're specifying.)

And I don't understand what it means for the files to be "accessible by JSP". If they are accessible by servlets then they are accessible by JSPs. Both can access files anywhere on the server.
reply
    Bookmark Topic Watch Topic
  • New Topic