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.

I think that should work.

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:

"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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.