0

I have searched for a long time, but found nothing.

I would like to read a file with Java from a specific UNC filename (\\\) and have to enter a user and a password. I do not want to use ftp or something on ssh (or better can't).

Something like this (pseudo code):

public static void readFile(File filename, URL fileURL, User userName, Password password){

    FileReader fr = new FileReader(filename, fileURL, userName, password);

   ... do something with the file ....

}

Is there a way to do this with Java? Thanks for your help.

[Edit] I would like to access a folder from a user in an other domain. So i have to submit the user and the password for this domain user.

Another case is to access the folder of an foreign user in unix systems. eg. my user ist located in /home/me and i want to access the folder of /home/you so i need to submit the passwort from the user "you".

7
  • Why do you need to provide a password? What protocol are you using? Commented Jun 4, 2012 at 9:53
  • You can't read files from URLs at all with FileReader. Not a real question. Commented Jun 4, 2012 at 9:56
  • I would like to access a folder from a user in an other domain. So i have to submit the user and the password for this domain user. Another case is to access the folder of an foreign user in unix systems. eg. my user ist located in /home/me and i want to access the folder of /home/you so i need to submit the passwort from the user "you". Commented Jun 4, 2012 at 9:59
  • @LStrike That has no bearing on my comment. If you have a URL, you can't use FileReader. Period. Do you perhaps mean UNC? Commented Jun 4, 2012 at 10:15
  • 1
    Ok, UNC may be more precise; path looks like this: \\servername\folder\file.txt Commented Jun 4, 2012 at 10:19

2 Answers 2

2

in the case of the UNC-path, you can give the JCIFS. (http://jcifs.samba.org/) a try. Its a prue Java inplementation of the Windows networking protocoll (e.g. Windows fileshare/map network drive).

Sign up to request clarification or add additional context in comments.

Comments

0

One way out is:

  1. Host a file on some http server like tomcat.
  2. Use Basic-Authentication to project the file access.

1 Comment

Sorry, this is not possible for me. I can not decide, where the file is "hosted"! See comment above.

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.