为什么文件被视为目录?

时间:2013-07-03 11:48:18

标签: android filenotfoundexception multipartentity

当我向multipartentity添加2个文件时,我收到了:

  

07-03 11:37:22.465:W / System.err(1112):java.io.FileNotFoundException:   /:打开失败:EISDIR(是一个目录)

我读过,如果我有同名的目录,可能会发生这种情况,但事实并非如此。

  

07-03 11:37:21.535: D/FilePath(1112): /mnt/sdcard/947808.jpg   07-03 11:37:21.535: D/FilePath(1112): /mnt/sdcard/126467-jugra.jpg

我该如何修复这样的例外?

我有以下代码,如下所示:

protected JSONObject doInBackground(String... params) {
            JSONObject json1 = null;
            JSONParser u = new JSONParser();
            photos = new ArrayList<String>();
            photos.add(photo1);
            photos.add(photo2);
            photos.add(photo3);
            List<File> f = new ArrayList<File>();

            for(String p:photos){
                Log.d("FilePath",p);
                if (p.equals("")|| p.equals("empty"))f.add(new File(p));
            }

            json1 = u.getJSONFromUrl(f);
            photos.clear();
            return json1;
        }
    public JSONObject getJSONFromUrl(List<File> f) {
        if (isOnline()) {

            String u = url;
            u = u + "?";
            try {
                // defaultHttpClient

                httpClient = HttpClientFactory.getThreadSafeClient();
                HttpPost httpPost = new HttpPost(url);
                MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                multipartEntity.addPart("action", new StringBody("upload_api"));
                for(File fs:f){
                    multipartEntity.addPart("photo_api[]", new FileBody(fs));
                }
//              
                httpPost.setEntity(multipartEntity);
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
                Log.d("data is sent", "true");

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                return null;

            }
            Log.d("wait", "true");
            try {
                Log.d("response","response");
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    // Log.d("JSON line", line);
                    sb.append(line + "\n");
                }
                is.close();
                json = sb.toString();
                Log.d("JSON", json);
                if (json.contains("error:2")) {
                    return null;
                }
                try {
                    jObj = new JSONObject(json);
                } catch (JSONException e) {
                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                    return null;
                }
//              pd.dismiss();
                return jObj;

            } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
                return null;
            }
            // try parse the string to a JSON object

        } // else promtError();
            // return JSON String
//      pd.dismiss();
        error();
        return null;

错误日志:

07-03 11:37:22.465: W/System.err(1112): java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 11:37:22.476: W/System.err(1112):     at libcore.io.IoBridge.open(IoBridge.java:416)
07-03 11:37:22.476: W/System.err(1112):     at java.io.FileInputStream.<init>(FileInputStream.java:78)
07-03 11:37:22.476: W/System.err(1112):     at org.apache.http.entity.mime.content.FileBody.writeTo(FileBody.java:92)
07-03 11:37:22.476: W/System.err(1112):     at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:162)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestEntity(AbstractClientConnAdapter.java:272)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:119)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-03 11:37:22.505: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.adapter.JSONParser.getJSONFromUrl(JSONParser.java:290)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.AddFillActivityApp$Upload.doInBackground(AddFillActivityApp.java:473)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.AddFillActivityApp$Upload.doInBackground(AddFillActivityApp.java:1)
07-03 11:37:22.505: W/System.err(1112):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-03 11:37:22.515: W/System.err(1112):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-03 11:37:22.515: W/System.err(1112):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-03 11:37:22.515: W/System.err(1112):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-03 11:37:22.546: W/System.err(1112):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-03 11:37:22.546: W/System.err(1112):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-03 11:37:22.556: W/System.err(1112):     at java.lang.Thread.run(Thread.java:856)
07-03 11:37:22.556: W/System.err(1112): Caused by: libcore.io.ErrnoException: open failed: EISDIR (Is a directory)
07-03 11:37:22.565: W/System.err(1112):     at libcore.io.IoBridge.open(IoBridge.java:405)
07-03 11:37:22.575: W/System.err(1112):     ... 24 more

任何人都可以建议我如何解决这个问题吗?

0 个答案:

没有答案
相关问题