簡體   English   中英

如何使用CIFS在Android Studio中訪問文件

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

我正在寫Android Studio中的代碼,但是有問題。 我想訪問Windows共享上的現有文件。 不幸的是,當我調試或運行代碼時,它對我不起作用。 我知道模擬器不是同一網絡,但是我下載了ping應用程序,然后將ping,imcp發送到了服務器上。 我下載了jcifs-1.3.19.jar,然后將其導入到項目中,但始終停留在某一時刻。

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

此代碼來自官方網站。 https://www.jcifs.org/src/docs/api/

我已經嘗試了很多方法。 為什么不能在模擬器上工作?

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)
{}

任何幫助表示贊賞。

什么是目標服務器? 僅當服務器支持SMBv1時,JCIFS才能連接到服務器。 新的Windows 10操作系統不支持此協議。 如果您需要可以連接到Windows 10的Java SMB庫,請查找jNQ庫(商業許可)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM