I need the route of a pdf file in my Android Project.
The file could be in raw or in assets folder.
I need to get the route because I must call using the File Class
Ex: File file = new File(path);
Thanks
Image:
http://img19.imageshack.us/img19/2303/capturaww.png
I am not quite sure what you mean, assuming you want to read to PDF file in your assets (res file) look here
Access PDF files from 'res/raw' or assets folder programmatically to parse with given methods
But if you want to get the file path of a folder, then look here
how to get file path from sd card in android
How to get the file path from URI?
Here is an example of how to get a file path (taken from the third link)
File myFile = new File(uri.toString());
myFile.getAbsolutePath()
Related
My application creates a file at this location
Absolute Path
/data/user/0/in.eaft.contentsecurityplayer/cache/.\epub\A-Room-with-a-View-morrison.epub\
Canonical Path
/data/data/in.eaft.contentsecurityplayer/cache/.\epub\A-Room-with-a-View-morrison.epub
i need to pass the real path to this library so that it opens the epub file
i need to open this file
folioReader.setConfig(config, true)
.openBook(filePath);
if i pass file path like /storage/sample.epub it opens but when i pass the above path file is not opening.
How to open this file from cache directory?
You need to add the following code as it is context based:
String cacheDir = context.getCacheDir();
This will give you the path
I have a method in my code which takes path of a folder as an argument. When I am using SD card I can simply give the path, but can I do the same with asset, and if so how? I need to write File f=new File(path) so that I can give f.getabsoultepath() as my argument. so what should be the value of path lets assume this is how my asset folder is orginzed and arc is my folder
Why can't I refer to a PDF file in my Android device?
I have a folder named "templates" in the root folder, and I have a PDF file in that. I've tried to refer to the file via the following:
File file = new File("/templates/myPDFFile.pdf");
but when I try to print file.exists(), it always returns me false.
Just as further information, my file hierarchy is:
root
-src
-com.example.text
-MyActivity.java
-templates
-MyPDFFile.pdf
and my code is stored in MyActivity.java.
How do I reference accurately to the PDF file?
You must put it in assets and get it from there like :
How to open a pdf stored either in res/raw or assets folder?
The file i want to open is located in the file:
/data/data/MY_PACKAGE/files/samplefile.txt
I have pulled the file from ddms and the desired content is in it
I just want to get the text file in order to parse it..
I tried the following:
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File xmlFile = new File(sdcard,"samplefile.txt");
but no joy...
Thanks in advance!!
Use getFilesDir(), not Environment.getExternalStorageDirectory(), to get at the root of internal storage, where your file resides.
In order to open a file stored within your applications private directory you must use openFileInput(String fileName). This will return a FileInputStream that you can then work with.
I have successfully stored bitmap in sdcard/Pictures folder in android 2.X , using following code
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "pic"+index+".jpg");
now, i want to retrieve all the images stored in that folder with out specifying name of the file.
You can get a list of all the files in a directory with
http://developer.android.com/reference/java/io/File.html#listFiles()
You probably want to add a filefilter so that you only return jpg files you are interested in
File filters you can read about here
http://developer.android.com/reference/java/io/FilenameFilter.html