使用java连接到Windows中的共享文件夹 [英] connecting to shared folder in windows with java

查看:1679
本文介绍了使用java连接到Windows中的共享文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过java连接到远程Windows机器上的共享文件夹,我在其中将我的域身份验证(用户名和密码)放在代码中,这是我的代码

I need to connect to a shared folder on a remote windows machine through java , where i put my domain authentication (username and password ) in the code , here is my code

 File file = new File("\\\\theRemoteIP\\webapps");   
    File[] files = file.listFiles();  
    System.out.println("acssed done");  

    for (int i = 0; i < files.length; i++)  
    {  
        String name = files[i].getName();  
        System.out.println(name);  
    }  

谢谢

推荐答案

您应该使用 SmbFile <来自 NtlmPasswordAuthentication http://jcifs.samba.org/rel =noreferrer> JCIFS 。这是一段简单的代码,向您展示如何操作:

You should use SmbFile and NtlmPasswordAuthentication from JCIFS. Here is a simple piece of code to show you how to do :

String url = "smb://yourhost/yourpath/";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "user", "password");
SmbFile dir = new SmbFile(url, auth);
for (SmbFile f : dir.listFiles())
{
    System.out.println(f.getName());
}

这篇关于使用java连接到Windows中的共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆