2015-08-13 64 views
0

我正在研究Android應用程序,其中我使用下面的代碼從資產複製文件。代碼工作正常,但我想知道它在哪裏創建新文件。默認情況下,FileOutputStream在Android上寫什麼目錄

try { 
    AssetManager am = getAssets(); 
    InputStream inputStream = am.open("key.p12"); 
    File file = createFileFromInputStream(inputStream); 

    credential = new GoogleCredential.Builder().setTransport(TRANSPORT) 
      .setJsonFactory(JSON_FACTORY) 
      .setServiceAccountScopes(SCOPES) 
      .setServiceAccountId("[email protected]") 
      .setServiceAccountPrivateKeyFromP12File(file) 
      .build(); 
} catch (GeneralSecurityException | IOException e1) { 
    e1.printStackTrace(); 
} 

private File createFileFromInputStream(InputStream inputStream) { 

    try{ 
     File f = new File("key.p12"); <--- where it is creating a new file ?? 
     OutputStream outputStream = new FileOutputStream(f); 
     byte buffer[] = new byte[1024]; 
     int length = 0; 

     while((length=inputStream.read(buffer)) > 0) { 
     outputStream.write(buffer,0,length); 
     } 

     outputStream.close(); 
     inputStream.close(); 

     return f; 
    }catch (IOException e) { 
     //Logging exception 
    } 

    return null; 
} 

感謝

+0

爲什麼不記錄文件的路徑,看看它在哪裏。可能這是在應用程序的緩存目錄中。 – rafid059

+0

它在應用程序私人文件夾中。參考:http://developer.android.com/intl/ja/guide/topics/data/data-storage.html#filesInternal –

回答

0

它正在以f.getAbsolutePath()創建。

相關問題