WelcomeTo
WelcomeTo

Reputation: 20591

Java. How to specify server path when upload files?

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);

Upvotes: 0

Views: 1353

Answers (2)

Ted Shaw
Ted Shaw

Reputation: 2306

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

Upvotes: 0

Ilya
Ilya

Reputation: 29703

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>

Upvotes: 1

Related Questions