0

私が受け取っているエラーは、この特定のファイルにあります

    FileInputStream fstream = new FileInputStream("data/data/com.demo.filesave/AllData");

== >> 07-27 10:41:30.710:java.io.FileNotFoundException:/data/data/com.demo.filesave/AllData(アクセスが拒否されました)

== >> 07-27 10:41:33.914:V / Log_tag(9274):java.io.FileNotFoundException:/data/data/com.demo.filesave/AllData/signature.png(アクセスが拒否されました)

//File SignSave = Environment.getExternalStorageDirectory();

FileWrite(SignSave,"confirmation"); 
    public  void FileWrite(File aPath,String aBody)
        {
            try 
            {
                //System.out.println("@@@@ Inside Try FileWrite @@@@");
                Log.e("BEFORE FILE","BEFORE FILE");
                aPath.createNewFile();
                Log.e("AFTER FILE","BEFORE AFTER");
                PrintWriter out1 = new PrintWriter(aPath);
                Log.e("AFTER FILE","AFTER PRINT WRITER");
                out1.write(aBody);  
                Log.e("AFTER FILE","AFTER WRITING");
                //System.out.println (aBody.trim());
                out1.flush();
                out1.close();
            }
            catch (IOException ioe)
            {
                //System.out.println("@@@@ Inside Catch FileWrite @@@@"); 
                ioe.printStackTrace();
            }

        }

== >> 07-27 10:41:33.921:W / System.err(9274):java.io.FileNotFoundException / mnt / sdcard(ディレクトリ)の行PrintWriter out1 = new PrintWriter(aPath);

マニフェストファイルの権限

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

問題を解決するのを手伝ってください。

よろしく、

4

2 に答える 2

0

data/data/ is a directory in the internal storage.

You are trying to write in the internal storage explicitly which, i think, is not allowed.

The permission:

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

gives your application to programmatically write to the sd card( or other 'external storage'). So if you are looking to store files in the cache directory , you should follow what the official documentation says :

If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data/<package_name>/files/

If you're using API Level 8 or greater, use getExternalCacheDir() to open a File that represents the external storage directory where you should save cache files.

于 2012-07-27T05:32:28.820 に答える
0

これを使用できます(rlはdrawingCacheが有効になっている相対レイアウトです)

newimg=rl.getDrawingCache();
String myPath=Environment.getExternalStorageDirectory()+"/saved_images";
File myDir=new File(myPath);
        try
        {
        myDir.mkdirs();
        }
        catch(Exception e)
        {
            Toast.makeText(getBaseContext(), "error: "+e.getMessage(), Toast.LENGTH_LONG).show();
        }
String fname = imagename+".jpg";
        File file = new File (myDir, fname);
        if (file.exists ()) file.delete ();
        String filename = file.getAbsolutePath ();
        FileOutputStream fos = null;
try {
        fos = new FileOutputStream (file);
        newimg.compress (CompressFormat.JPEG, 95, fos);
        Toast.makeText(getBaseContext(), filename+"  saved", Toast.LENGTH_LONG).show();
        } catch (Throwable ex) {
            Toast.makeText(getBaseContext(), "error: "+ex.getMessage(), Toast.LENGTH_LONG).show();
        }
于 2012-07-27T05:30:46.737 に答える