Java URL自动更改导致错误“;“未找到文件”;当我从url下载时

Java URL自动更改导致错误“;“未找到文件”;当我从url下载时,java,android,Java,Android,LogCat:03-05 05:11:35.620:W/System.err(3437):java.io.FileNotFoundException: 这个问题是url“dantri.com.vn/xa hoi.rss”更改为“m.dantri.com.vn/xa hoi.rss” 请帮帮我!。谢谢大家。错误在这里: try { URL url = new URL("http://dantri.com.vn/xa-hoi.rss"); HttpURLConnect

LogCat:03-05 05:11:35.620:W/System.err(3437):java.io.FileNotFoundException:

这个问题是url“dantri.com.vn/xa hoi.rss”更改为“m.dantri.com.vn/xa hoi.rss” 请帮帮我!。谢谢大家。

错误在这里:

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();
    }
替换为:

 OutputStream fos = new FileOutputStream("/sdcard/xa-hoi.rss");

请确保您已在清单内写下以下内容

OutputStream fos = new FileOutputStream("xa-hoi.rss");

使用而不是静态字符串获取SD卡路径,如下所示:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
并确保您已在
AndroidManifest.xml
中添加SD卡权限:-

String sdcardpath = Environment.getExternalStorageDirectory().getAbsolutePath();
OutputStream fos = new FileOutputStream(sdcardpath+"/xa-hoi.rss");


您是否已获得在清单中写入外部存储的权限?不要编辑答案以作出响应-而是单击“添加评论”链接并添加评论。谢谢,但此问题是url“dantri.com.vn/xa hoi.rss”更改为“m.dantri.com.vn/xa hoi.rss”好的。。。那么,您的真实手机是指移动网站而不是原始网站吗?谢谢,但这个问题是url“dantri.com.vn/xa hoi.rss”更改为“m.dantri.com.vn/xa hoi.rss”
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />