您可以使用JCIFS库实现CIFS/SMB网络协议......简而言之,它允许您通过网络和/或具有共享文件夹的Windows PC发送和接收文件。
实施例:
private boolean startSmbTransfer(String filename) {
boolean IS_SUCCESS = true;
File sourse = new File(Environment.getExternalStorageDirectory()
+ "/FolderName/" + filename);
final String NETWORK_FOLDER = "smb://PC-NAME/FOLDER-NAEME/";
SmbFileOutputStream sfos = null;
InputStream is = null;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
null);
String path = NETWORK_FOLDER + sourse.getName();
System.out.println("Path: " + path);
SmbFile sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
byte[] buf = new byte[512];
is = new FileInputStream(sourse);
int c = 0;
while ((c = is.read(buf, 0, buf.length)) > 0) {
sfos.write(buf, 0, c);
sfos.flush();
}
} catch (Exception e) {
e.printStackTrace();
IS_SUCCESS = false;
} finally {
try {
sfos.close();
is.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
IS_SUCCESS = false;
}
}
return IS_SUCCESS;
}
检查下面的链接详细信息和例如使用该库, using JCIFS library in android
感谢。但是应该是本地的。我知道端口转发是什么,但我怎么用它来解决我的问题? – ReZa
您可以手动设置您的计算机的IP地址(为了防止它有随机的IP地址),然后尝试连接。 – Taha
或者,您可以为本地电脑设置一个域名。我发现[这](http://lifehacker.com/124804/geek-to-live--how-to-assign-a-domain-name-to-your-home-web-server)。希望这可以帮助。 – Taha