0

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);
}
out.flush();

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

6
Contributors
6
Replies
29
Views
3 Years
Discussion Span
Last Post by JamesCherrill
0

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

0

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:

"c:/Users/myname/directory/filename"

instead of

c:\\Users\\myname\\directory\\filename"

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

0

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.

0

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.