如何将bin文件从内部存储器上传到android中的http服务器?
我收到权限被拒绝错误。
String url = "url_path";
String PATH = "/storage/emulated/0/data/";
Log.v("response path ", "PATH: " + PATH);
File file = new File(PATH,
"/test.bin");
if(file.exists()){
Log.d("response : "," file available");
} else {
Log.d("response : "," file not available");
}
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
错误日志:
java.io.FileNotFoundException:/storage/emulated/0/data/test.bin(Permission denied)
答案 0 :(得分:0)
您只拥有应用程序数据目录的权限。除非您使用了root设备。
或强>
系统应用