0

I need to programmatically save files (and create directories) to another server. How I can achieve this? In the other server there is a shared directory(write access), and want to write files here. I use

FileOutputStream file = new FileOutputStream(fullFileName, false);

Where fullFileName is

////SRV0105-FSACL01/SharedDirectory/directoriesCreatedByMe/filename.xls

I think server path is written not correct, may here some extra slashes?

EDIT: Operation fails on dir.mkdirs() command (this command return false);

1
  • Did you try with backslashes "\"? Commented Aug 20, 2012 at 14:30

2 Answers 2

1
org.apache.commons.io.FileUtils.copyFile(new File("////MY-COMP/Documentations/Java/Maven.pdf "), new File("D:/p.pdf"));

working well

org.apache.commons.io.FileUtils.copyFile(new File("//MY-COMP/Documentations/Java/Maven.pdf "), new File("D:/t.pdf"));

also working well

Use class org.apache.commons.io.FileUtils

  <dependency>
     <groupId>commons-io</groupId>
     <artifactId>commons-io</artifactId>
     <version>1.4</version>
     <type>jar</type>
  </dependency>
Sign up to request clarification or add additional context in comments.

Comments

0

if both your 2 servers (one server is running java, the other is used to store file) are windows, you can setup \ServerComputerName\ShareName as Driver as F: and write F://filename.xls If both are linux, start NFS service on the target server and mount on the exported folder in the server which java is running on. if mixed environment, consider sftp solution, you can refer to JSch

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.