我正在使用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("xxxxxxxxxxxxxxxx@developer.gserviceaccount.com")
.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 :(得分:0)
正在f.getAbsolutePath()
创建。