在我们的应用程序中,我们将pdf文件存储到内部存储中.现在我想获取其文件路径并需要存储到DB中.请告诉我如何获取其文件路径.下面的代码:
public void storeIntoInternalMem(byte[] databytes, String name) { try { FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE); fileOuputStream.write(databytes); fileOuputStream.close(); } catch (IOException e) { e.printStackTrace(); } }
d3m0li5h3r.. 31
您可以使用Context.getFilesDir()
方法获取内部存储的路径
编辑
使用此行时FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
,内部存储路径由方法的默认实现获得openFileOutput()
.将在具有指定名称的该位置创建新文件.现在,当您想要获取同一文件的路径时,可以使用它getFilesDir()
来获取创建文件的目录的绝对路径.你可以这样做: -
File file = new File(getFilesDir() + "/" + name);
String dir = getFilesDir().getAbsolutePath();
您可以使用Context.getFilesDir()
方法获取内部存储的路径
编辑
使用此行时FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
,内部存储路径由方法的默认实现获得openFileOutput()
.将在具有指定名称的该位置创建新文件.现在,当您想要获取同一文件的路径时,可以使用它getFilesDir()
来获取创建文件的目录的绝对路径.你可以这样做: -
File file = new File(getFilesDir() + "/" + name);