Android ftpUpload错误:java.lang.IllegalArgumentException:
我想上传一个图像到服务器。这是我的密码: MainAcitvity.java:Android ftpUpload错误:java.lang.IllegalArgumentException:,android,image-uploading,Android,Image Uploading,我想上传一个图像到服务器。这是我的密码: MainAcitvity.java: String filePath = Environment.getExternalStorageDirectory()+ "/cloze_screenshots/20141014_055246.jpg"; boolean ftpclient.ftpUpload(filePath,"20141014_055246.jpg","./bigmim
String filePath = Environment.getExternalStorageDirectory()+
"/cloze_screenshots/20141014_055246.jpg";
boolean ftpclient.ftpUpload(filePath,"20141014_055246.jpg","./bigmimi/public_html/testing/"+"947917688555565/",cntx);
ftpclient.java:
public boolean ftpUpload(String srcFilePath, String desFileName,
String desDirectory, Context context)
{
boolean status = false;
try {
// FileInputStream srcFileStream = new FileInputStream(srcFilePath);
FileInputStream srcFileStream = context.openFileInput(srcFilePath);
// change working directory to the destination directory
//if (ftpChangeDirectory(desDirectory)) {
status = mFTPClient.storeFile(desFileName, srcFileStream);
//}
srcFileStream.close();
return status;
}
catch (Exception e) {
//Log.d(TAG, "upload failed: " + e);
Log.e("go","error: "+ e);
}
return status;
}
我得到一个错误:
error: java.lang.IllegalArgumentException: File /storage/emulated/0/cloze_screenshots/20141014_055246.jpg contains a path separator
任何建议都将不胜感激。作为文档openFileInput中的统计信息
打开与此上下文的应用程序包关联的私有文件
用于阅读
参数
命名要打开的文件的名称;不能包含路径
分离器
i、 e.openFileInput不接受路径,只接受文件名。如果您想访问路径,请使用新文件路径从路径获取文件名,然后将其传递到openFileInput中
在代码更改中
FileInputStream srcFileStream = context.openFileInput(srcFilePath);
到
编辑
您的文件在SD卡中,并且您正在使用openFileInput打开内部文件。因此,要从SD卡获取文件,请使用
File mFile = new File(srcFilePath);
并使用srcFileStream作为
而不是
FileInputStream srcFileStream = context.openFileInput(srcFilePath);
我收到新错误:错误:java.io.FileNotFoundException:/data/data/com.example.friendpicker/files/20141014\u 072939.jpg:打开失败:没有这样的文件或directory@hiein2003您是否按照建议进行了更改。请将您的代码也发布到update@hiein2003看起来你的图像文件在SD卡中,你正试图从内部获取这些文件我按照您的建议更改了代码:File f=new FilesrcFilePath;字符串文件名=f.getName;FileInputStream srcFileStream=context.openFileInputfilename;对吗?非常感谢!这对我帮助很大。
FileInputStream srcFileStream = new FileInputStream(mFile);
FileInputStream srcFileStream = context.openFileInput(srcFilePath);