OS: macbook
I wanna read remote file in Java. I test it on my local computer first.
I tried to use
File
, but you guys told meFile
can only be used on local file system, thanks.public static void main(String[] args) throws URISyntaxException { URI uri = new URI("file://127.0.0.1/Users/jian/Public/logfiles/Hadoop/hdp_log1.log"); File file = new File(uri); System.out.println(file.exists()); }
I find a library for Macbook, Samba JCIFS, from this link access to file using Java with Samba JCIFS . Here is my code :
public static void main(String[] args) throws URISyntaxException, MalformedURLException, SmbException { NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("","jian", "ywnk"); SmbFile smbFile = new SmbFile("smb://127.0.0.1/Users/jian/Public/logfiles/Hadoop/hdp_log1.log",auth); System.out.println(smbFile.exists()); }
Then I got this error:
Exception in thread "main" jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
username is the same as I run who am i
in terminal, and password is my login password. I don't know why I get this username or password incorrect error.
Thanks for your guys help.