简体   繁体   English

如何使用CIFS在Android Studio中访问文件

[英]How to access a file in Android studio with CIFS

I'm writing to code in Android Studio, but I have a problem. 我正在写Android Studio中的代码,但是有问题。 I would like to access to exist file on windows shares. 我想访问Windows共享上的现有文件。 Unfornately when I debugging or running the code, it is not working for me. 不幸的是,当我调试或运行代码时,它对我不起作用。 I know that emulator is not same network, but I downloaded ping app and I sent ping, imcp to server what worked. 我知道模拟器不是同一网络,但是我下载了ping应用程序,然后将ping,imcp发送到了服务器上。 I downloaded jcifs-1.3.19.jar then I imported in project, but always stuck at one point. 我下载了jcifs-1.3.19.jar,然后将其导入到项目中,但始终停留在某一时刻。

SmbFileInputStream in = new SmbFileInputStream("smb://host/c/My Documents/somefile.txt", auth);

This code is from the official site. 此代码来自官方网站。 https://www.jcifs.org/src/docs/api/ https://www.jcifs.org/src/docs/api/

I've tried it in many ways. 我已经尝试了很多方法。 Why is not working on emulator? 为什么不能在模拟器上工作?

import jcifs.smb.*;
try{
jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "username", "password");
SmbFileInputStream in = new SmbFileInputStream("smb://host/c/My Documents/somefile.txt", auth);
byte[] b = new byte[8192];
int n;
while(( n = in.read( b )) > 0 ) {
    System.out.write( b, 0, n );
}
}
catch(Exeption e)
{}

Any help is appreciated. 任何帮助表示赞赏。

What is the target server? 什么是目标服务器? JCIFS can connect to a server only when the server supports SMBv1. 仅当服务器支持SMBv1时,JCIFS才能连接到服务器。 New Windows 10 OSs do not support this protocol. 新的Windows 10操作系统不支持此协议。 If you need a Java SMB library that can connect to Windows 10, look for the jNQ library (commercial license). 如果您需要可以连接到Windows 10的Java SMB库,请查找jNQ库(商业许可)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM