access to file using Java with Samba JCIFS

牧云@^-^@ 提交于 2019-11-26 22:02:41

You are making this harder than it should be. Please follow the below steps and make sure the shared folder you are creating has write access for this user you are using.

  1. download the jar file http://jcifs.samba.org/ (there is only one jar file)
  2. copy and paste the below code with your information for user name, password and shared folder and that's all you need

I was running this on Linux and wanted to write to a Windows box so you want to create a shared folder and put the shared folder name in the below variable if you don't know how to create shared folder on windows ...use google as always

    String user = "your_user_name";
    String pass ="your_pass_word";

    String sharedFolder="shared";
    String path="smb://ip_address/"+sharedFolder+"/test.txt";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
    SmbFile smbFile = new SmbFile(path,auth);
    SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
    smbfos.write("testing....and writing to a file".getBytes());
    System.out.println("completed ...nice !");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!