0

当我运行此 URL 并尝试保存 t\in .mp4 格式时,它会给出 FileNotFound 异常。如果我从浏览器尝试相同的 URL,存储为 .mp4 格式 http://vimeo.com/moogaloop/play/clip:7926539/5cd4f7989ee0cb5018c131260aa1fc8c/1309860388/

这是我的代码:

String storage = Environment.getExternalStorageState();
    Log.i("System out", "" + storage);
    File rootsd = Environment.getExternalStorageDirectory();
    Log.d("ROOT PATH", "" + rootsd.getAbsolutePath());

    File mydir = new File(rootsd.toString() + "/unplugger");
    Log.i("DIR PATH", "" + mydir.getAbsolutePath());
    mydir.mkdir();

    URL u;
    try {
        u = new URL(
                "http://vimeo.com/moogaloop/play/clip:7926539/5cd4f7989ee0cb5018c131260aa1fc8c/1309860388/");

        HttpURLConnection c = (HttpURLConnection) u.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);

        c.connect();

        FileOutputStream f = new FileOutputStream(new File(mydir + "/"
                + "myVideo.mp4"));

        InputStream in = c.getInputStream();

        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = in.read(buffer)) > 0) {
            f.write(buffer, 0, len1);
        }
        f.close();
        c.disconnect();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.i("System out","malformed :"+e.getMessage());
        Log.i("System out","malformed :"+e.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.i("System out","io: "+e.getMessage());
        Log.i("System out","io: "+e.toString());
    }

提前致谢。

4

1 回答 1

2

改变这块:

new File(mydir + "/" + "myVideo.mp4")

改为:

new File(mydir, "myVideo.mp4")
于 2011-07-05T11:52:35.267 回答