我是一个新手在android方面,我想从我的Android设备上拍摄一张照片并将其保存到我的PC的共享文件夹中,这是一个简单的任务,我已经完成了这个任务,但现在我遇到了困难,我想先创建一个文件夹,例如:myserver/share, 我不想在这里放图片,我想像这样创建一个新的文件夹: myserver/share/new folder。我希望所有的图片都放在这个新建的文件夹中。到目前为止,我尝试了以下代码:
但是我遇到了路径不存在的异常,如下所示:
try
{
String url = "smb://serverpath/share/"+ edittext.getText().toString() +"/Test.jpg";
SmbFile smfile = null;
try {
NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication("domain","myuser","pass");
smfile = new SmbFile(url, auth);
if(!smfile.exists())
{
smfile.mkdirs();
}
// output is like smb://mypc/e/sharedfoldername/file.txt;
SmbFileOutputStream out = new SmbFileOutputStream(smfile);
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
out.write(byteArray);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
e.getCause();
}
但是我遇到了路径不存在的异常,如下所示:
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: jcifs.smb.SmbException: The system cannot find the path specified.
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:545)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbTransport.send(SmbTransport.java:645)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbSession.send(SmbSession.java:230)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbTree.send(SmbTree.java:119)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbFile.send(SmbFile.java:770)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at jcifs.smb.SmbFile.mkdir(SmbFile.java:2511)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at com.test.test.cameraapplication.MainActivity$2.run(MainActivity.java:180)
09-20 12:01:21.691 18341-19275/com.test.test.cameraapplication W/System.err: at java.lang.Thread.run(Thread.java:818)