-1

他のパッケージ "/data/data/targetPackage" から "/data/data/myPackate" にファイルをコピーしようとしましたが、うまくいきません。私はリクエストsu許可を持っています

p = Runtime.getRuntime().exec("su");   
// Attempt to write a file to a root-only  
DataOutputStream os = new DataOutputStream(p.getOutputStream());  
os.writeBytes("chmod 777 /data/data/targetPackage/databases"+"\n");  
// Close the terminal  
os.writeBytes("exit\n");  
os.flush();  
try 
{  
    p.waitFor();  
    if (p.exitValue() != 255) 
    {  
      // TODO Code to run on success  
      toastMessage("root");  
      //accsessDB();
    }  
    else 
    {  
       // TODO Code to run on unsuccessful  
       toastMessage("not root");  
    }  
} 
catch (InterruptedException e) 
{  
   // TODO Code to run in interrupted exception  
   toastMessage("not root");  
}  

そしてこのコードコピー

File f=new File("/data/data/targetPackage/databases/targetFile");
InputStream input = new FileInputStream(f);
new File("/data/data/myPackate/databases").mkdir();
File f2=new File("/data/data/myPackate/databases/targetFile");
OutputStream output = new FileOutputStream(f2,true);    
byte[] buf= new byte[1024];
toastMessage(Integer.toString(input.read(buf)));
int len;
while((len=input.read(buf))>0) 
{
    output.write(buf, 0,len);
}
output.close();
input.close();

私を助けてください

4

1 に答える 1

1

これを試してみてください..

private void copyFile()
 {
     try{
     if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
        } else {
            File file = new File(Environment.getExternalStorageDirectory()
                 +File.separator
                 +"App"
                 +File.separator                         
                 +"app"
                 +File.separator
                 +"images"
                 +File.separator
                 ); //file name
            file.mkdirs();
            File source= new File(filePath);
            File destination= new File(file,nameimage);
            newloc=Environment.getExternalStorageDirectory()+"/"+"App"+"/"+"app"+"/"+"images"+"/";
           newimgloc=Environment.getExternalStorageDirectory()+"/"+"App"+"/"+"app"+"/"+"images"+"/"+nameimage;
            if (source.exists()) {
                FileChannel src = new FileInputStream(source).getChannel();
                FileChannel dst = new FileOutputStream(destination).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();

                File dir = Environment.getExternalStorageDirectory();
                if(dir.exists()){

                    toname=generatePin();
                    File from = new File(newloc,nameimage);
                    File to = new File(newloc,toname+".jpg");                       
                     if(from.exists())
                        from.renameTo(to);
                     filePath=newloc+toname+".jpg";
                     nameimage=toname+".jpg";
                     filedel();
                }


            }
        }
    }catch (Exception e) {

         System.out.println(e);
         Toast.makeText(getApplicationContext(), "Catch",Toast.LENGTH_SHORT).show();
    }

}

于 2012-12-18T10:03:49.120 に答える