Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write files to a remote directory using java?

I have the directory mapped on my machine so that I can browse and write to it via Windows explorer. I would like to write files via java.

File f = new File("http://dev1:8080/data/xml/myTestFile123.xml");

f.createNewFile();

I am getting the following error:

Exception in thread "main" java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(Unknown Source)
    at MainTest.createTestFile(MainTest.java:156)
    at MainTest.main(MainTest.java:72)

Is there any way to write files to a mapped directory that has the http:// in front? Because thats the way the directory is provided to me. It is a virtual directory that an oracle database is creating.

like image 713
joe Avatar asked Dec 09 '22 19:12

joe


2 Answers

My understanding is that you are trying to write to an Oracle XML DB Repository. Oracle XML DB Repository is a feature that has been introduced by Oracle9i Database Release 2 for XML storage and that can be accessed through FTP or HTTP/WebDAV. In your case, it looks like you're trying to use HTTP/WebDAV.

As explained in the WedDAV page on Wikipedia:

WedDAV is a set of extensions on top of HTTP that allows users to edit and manage files collaboratively on remote World Wide Web servers.

In other words, adding files, deleting them, renaming them, etc in a WebDAV repository is done using HTTP words: PUT, DELETE, MOVE, etc (see RFC 4918 for more details).

Consequently, interacting with a WebDAV server can be done using classes from java.net.

Or you could use a higher level API like Jakarta Commons HttpClient.

Or you could use a Java WebDAV client like the one provided by the Slide project. This article shows how to do it and it looks simple. However, as the Slide project is now retired, I wouldn't recommend it.

Luckily (or not), the Apache Jackrabbit project is an alternative to Slide... but AFAIK the WebDAV support in Jackrabbit is more focused on server-side implementations than clients. Anyway, you'll find some code samples in this thread on the jackrabbit-users mailing list.

I think I'd choose HttpClient and use the Tutorial or the Sample Code as starting points.

like image 55
Pascal Thivent Avatar answered May 11 '23 10:05

Pascal Thivent


I'm not really sure what I'm talking about here (not a Java guy) but although you may "have it mapped" you're passing in a URL instead of an expected file system path. If (for example) you have a mapped drive under Windows, use the drive letter assigned.

like image 30
5 revs, 3 users 96% Avatar answered May 11 '23 08:05

5 revs, 3 users 96%