如何将bin文件从android内部存储上传到android

时间:2018-06-04 05:39:26

标签: android httpserver bin internal-storage

如何将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)

1 个答案:

答案 0 :(得分:0)

您只拥有应用程序数据目录的权限。除非您使用了root设备。

系统应用