android上的BufferedWriter总是抛出异常

时间:2015-11-24 09:54:17

标签: java android

当我运行此代码时,总是给我异常“2Error !!”

我需要将网站sitemap.xml保存到ImageData.html中以便以后提取数据!

private class Loading extends AsyncTask<Void,Void,Void>{


    @Override
    protected Void doInBackground(Void... params) {
        try {
            URL url = new URL("http://example.com/post-sitemap.xml");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            BufferedWriter writer = new BufferedWriter(new FileWriter("ImageData.html"));
            String line;
            while ((line = reader.readLine()) != null) {
                writer.write(line);
                writer.newLine();
            }
            reader.close();
            writer.close();
        } catch (MalformedURLException e) {
            System.out.println("1Error!!");
        }  catch (IOException e) {
            System.out.println("2Error!!");
        }return null;}

我并没有忘记将权限放在AndroidManifest.xml

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

栈跟踪

  

W:java.io.FileNotFoundException:/CategoriesData.html:open failed:   EROFS

     

W:在libcore.io.IoBridge.open(IoBridge.java:409)

     

W:在java.io.FileOutputStream。(FileOutputStream.java:88)

     

W:在java.io.FileOutputStream。(FileOutputStream.java:73)

     

W:在java.io.FileWriter。(FileWriter.java:80)

     W:at   codev.piclib.MainLoading $ Loading.doInBackground(MainLoading.java:242

     W:at   codev.piclib.MainLoading $ Loading.doInBackground(MainLoading.java:214

     

W:在android.os.AsyncTask $ 2.call(AsyncTask.java:288)

     

W:在java.util.concurrent.FutureTask.run(FutureTask.java:237)

     

W:在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)

     W:at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

     W:at   java.util.concurrent.ThreadPoolExecutor中$ Worker.run(ThreadPoolExecutor.java:587)

     

W:在java.lang.Thread.run(Thread.java:841)

     

W:引起:libcore.io.ErrnoException:open failed:EROFS(只读)   文件系统)

     

W:at libcore.io.Posix.open(Native Method)

     

W:在libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)

     

W:at libcore.io.IoBridge.open(IoBridge.java:393)

     

W:......还有11个

0 个答案:

没有答案