hi everyone. i've used the following way to store the uploaded files into D: drive of my windows machine from Tomcat server and it works pretty goood.

private final String directoryPath="D:\\uploadedFiles\\";

File f=new File("D:\\uploadedFiles\\"+fileName);
InputStream in=file.getInputStream();       
OutputStream out=new FileOutputStream(directoryPath+fileName);

byte[] buff=new byte[4096];
int count=0;
while((count=in.read(buff))!=-1) {
    out.write(buff, 0, count);

now, I want to store the same uploaded files in the linux machine which hosts the Tomcat server. Can i just change the directoryPath in order to store the files in that folder? E.g. /tmp/uploadedFiles ?? Please help me.
Thank you.

Edited by cool_zephyr

3 Years
Discussion Span
Last Post by JamesCherrill

Is the server on network? If it is, you might have to some additional code to create and manage a connection to the server.


First off, Linux doesn't accept Windows-style back-slash characters for directory delimiters in a path. On the other hand, Windows will handle Linux-style forward slashes just fine, so when referring to file paths in Java, use '/' instead of '\'. IE, use:


instead of


The first case is universally valid. The second case is ONLY usable in Windows.


thank you for your replies

@djslavens - i think the harddisk and the server are the same machine

could you also tell me which folder would be the best for storing those files in linux?? because I have very little experience with that.


to get path separators in an operating system independent fashion, use System.getProperty("file.separator").
Of course that does not guarantee your directory will be correct, as you're hardcoding a drive name there which Linux (or Mac, or pretty much anything except Windows) doesn't understand.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.