0

I have a program that has to read a file from network location - something like this

String sFileSource = "//MyShared/location/fileName.txt" ;
File inputFile = new File(sFileSource);

try {
    ffBuffer = new BufferedReader(new FileReader(inputFile));           
} 
catch (FileNotFoundException e) { // should never happen
}

Now, the problem is that that shared location is on the different network domain and accessible only using domain credentials How can I embed entering the credentials into this java program ? The problem is that when ran from different PCs it fails due to login.

Dmitriy Ryabin
  • 363
  • 3
  • 16

1 Answers1

0

Reading a file like that is not a secure way to do it, because you will expose your user domain credentiels. Reversing the java app could lead to that, so it's better to use an ftp server for that.

The way I have done it before:

Read remote file in java which needs username and password

Mohamed
  • 131
  • 1
  • 5
  • Thanks. No problem with FTP. I already made a version of the code to do that. Unfortunately, setting that location as an ftp site might be not possible for our organization. .. :( – Dmitriy Ryabin Nov 20 '19 at 17:48
  • 1
    I see, you can create a user in the same remote machine and give it limited access. Then use SMB protocole to acces remote machine files, there is a Java Library to make that easy for you [https://github.com/AgNO3/jcifs-ng] – Mohamed Nov 21 '19 at 18:41