2013-05-09 2 views
0

파일을/dev에 쓰려고하는데 다음과 같은 코드가 있습니다. log.what에서 오류가 발생합니다.이 문제를 테스트하기 위해 에뮬레이터를 사용하고 있습니다. 이것은 실제 장치에서 수행해야합니까?android

try { 
     process = Runtime.getRuntime().exec("su"); 
     OutputStream os = process.getOutputStream(); 
     DataOutputStream dos = new DataOutputStream(os); 
     String cmd = "echo 'hello world'> /dev/pttycmd1"; 
     String cmd1 = "echo 'hello world2'> /dev/pttycmd2"; 
     dos.writeBytes(cmd); 
     dos.writeBytes(cmd1); 
     dos.flush(); 
     File f = new File("/dev/pttycmd1"); 
     if(f.exists()) 
     { 
      /* do something */ 
      Log.d("success", "File exists"); 
     } 
     else 
     { 
      Log.d("error", "File does not exists"); 
       //file.mkdirs(); 
       //And your other stuffs goes here 
     } 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

답변

1

/dev은 일반 사용자가 쓸 수 없습니다. 아마도 root은 쓸 수 없습니다 /dev