java - 当我从 url 下载时,URL 自动更改导致错误 "file not found"

标签 java android

try {
        URL url = new URL("http://dantri.com.vn/xa-hoi.rss");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.connect();

        InputStream is = new BufferedInputStream(url.openStream());
        OutputStream fos = new FileOutputStream("/sdcard/xa-hoi.rss");

        byte[] buffer = new byte[1024];
        int bufferLenght = 0;
        while((bufferLenght = is.read(buffer)) != -1){
            fos.write(buffer, 0, bufferLenght);
        }
        fos.close();
        fos.flush();
        is.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e){
        e.printStackTrace();
    }

LogCat: 03-05 05:11:35.620: W/System.err(3437): java.io.FileNotFoundException: http://m.dantri.com.vn/xa-hoi.rss .

此问题是 url "dantri.com.vn/xa-hoi.rss"更改为 "m.dantri.com.vn/xa-hoi.rss" 请帮我!。谢谢大家。

最佳答案

确保您在 list 中编写了以下内容。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

关于java - 当我从 url 下载时,URL 自动更改导致错误 "file not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216651/

相关文章:

java - 如何使用 GSON 将 JSON 数组序列化为 Java 对象?

java - 如何访问另一个类引发的异常

java - 从 Jenkins 到 Tomcat 部署 war 时出现 OutOfMemoryError

android - 如何完成当前 Android 任务中的所有 Activity ?

java - 同步块(synchronized block)中的notify()

java - 来自不同类的 JButton

android - Gson 生成的 apk 和 Debug模式的不同行为

android - Android 设备上的屏幕兼容性

android - 将图像从android上传到webservice

android - Cordova 运行安卓 : ANDROID_HOME not set and android not in my path