如何获得文件的文件路径,从内部存储在机器人 [英] How to get file path of file from internal storage in android
问题描述
在我们的应用中都存储PDF文件转换为内部storage.Now我想要得到它的文件路径和需要存储到数据库。请告诉我如何得到它的文件路径。 低于code:
公共无效storeIntoInternalMem(byte []的databytes,字符串名称){
尝试
{
FileOutputStream中fileOuputStream = openFileOutput(姓名,MODE_PRIVATE);
fileOuputStream.write(databytes);
fileOuputStream.close();
}赶上(IOException异常E)
{
e.printStackTrace();
}
}
您可以使用 Context.getFilesDir()
方法来获取路径内部存储
修改
使用此行的FileOutputStream fileOuputStream = openFileOutput(姓名,MODE_PRIVATE)时;
是由默认实现获得的内部存储路径 openFileOutput( )
方法。一个新的文件,在具有指定名称的位置创建。现在,当你想获得相同的文件的路径,可以使用 getFilesDir()
得到的绝对路径创建该文件的目录。你可以这样做: -
档案文件=新的文件(getFilesDir()+/+姓名);
In our application we are storing pdf files into internal storage.Now i want to get its filepath and need to store into DB. Please tell me how to get its file path. below code:
public void storeIntoInternalMem(byte[] databytes, String name) {
try
{
FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
fileOuputStream.write(databytes);
fileOuputStream.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
you can use Context.getFilesDir()
method to get the path to the internal storage
Edit
when using this line FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
the internal storage path is obtained by the default implementation of the openFileOutput()
method. A new file is created at that location with the specified name. Now when you want to get the path of the same file, you can use the getFilesDir()
to get the absolute path to the directory where the file was created. You can do something like this :-
File file = new File(getFilesDir() + "/" + name);
这篇关于如何获得文件的文件路径,从内部存储在机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!