Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to a file server  RSS feed

 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,

I need to write .pdf documents to a file server. I need to make a connection to it and then store the files in a directory. The file server has permissions set so I need to pass a user name and password - I think.
The file server has multiple drives and I only want to write to a specific drive and a specific directory.

I started out with FileInputStream and FileOutputStreams and this worked fine -- locally.
I then figured on using a URLConnection to connect to the
file server and an OutputStreamWriter. How do I put them together? . What I have so far:



I want the files on the D drive but I'm not exactly sure how to specify that.

Help!

~J
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to use URL to write a file to a server, you need a web server on the receiving end configured to accept a file upload. Do you have such a thing?
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Websphere to host my application, and I have a JSP page that the user can use to browse for .pdf files locally. It uses an InputStream to get the pdf and store it in a byte[] which is added to a map and put into session.
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that.....

I'm using Websphere to host my application, and I have a JSP page that the user can use to browse for .pdf files locally. It uses an InputStream to get the pdf and store it in a byte[] which is added to a map and put into session.



But on the File server there is no web server running.
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should probably clarify that the first bunch of code is more of a proof of concept. I want to be able to write to the file server in the correct directory. Then I will incorporate it into the application and use the .pdf file the user has uploaded.

hope that helps
~J
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you need two pieces. You need something on your web server to accept the file upload (servlets.com or Apache Commons have done the heavy lifting) and something on your file server to accept the file transfer. The second part depends on what your file server exposes. Does it have FTP? NFS? Can you mount a network drive?
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK according to the group setting up the file server, they will use UNC and all I need to do is specify \\servername\share in order to write my .pdf's. Does this mean I only need the FileOutputSream?

I think I'm still missing something.
~J
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UNC paths are perfectly legal in Java. Of course, you'll have to escape those slashes.
By the way, in your original code:

You are correct, this is not right. That writes the input stream instance, not the input stream data. Your code to copy the data should look the same as you had it for a local file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!