Get filename of file from web directory - android

I'm trying to simply get the filename of a file from an online directory. The directory only has one file in it. The filename is actually the version number. If the filename is "newer" than the file that I already have stored on the android, it will download the file and replace it. I already know how to download the file. I'm not sure if android has some sort of built-in directory lister or if I need to create a PHP file that will display the files, then somehow open and read that in and use that as my path. Any help would be greatly appreciated.

You'll want to write that PHP script to return the file name. With that, you can do a straight download from the server.

Related

Where can I see the file in path getApplicationContext().getFilesDir()

I am using the below code to create a file in android as
File file = new File(getApplicationContext().getFilesDir(), "content.txt");
I want to open the file in my phone. I went to the path
Local storage/Android/data/<my package>/files/
However, I cannot see the file. My Android version is 5.0.1. What is happen? One more thing, Do you think the above way is a good way to save file? What is common path to save a file in Android? Thanks
The file locates in /data/data/[your package]/files,it's app private directory.
It's a good way or not depends on the purpose of your file.
if you want your file visable only to you(the app developer),the folder is right
if the file can be visable to others and the file is large,then you can put it to sdcard folder
if you want the file stay even if your app being removed,you shouldn't put it in this folder.Because when an app removed,the all data in /data/data/[package name]/ will be deleted also.
You find in:
/data/data/[your package name]/files/

How can i insert a .bin created on desktop file into apk

I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.

How to access all file without unzip any zip file in android?

I am working on reading epub3 file and i want to access all files which used for create epub3 without *unzip it.*
any suggestion or solution would be appreciated....
I have tried to solve this and i got the following solution.
Zip is a one type of file Which include many directory and files so we can't get it in directory and file format.
We can only get it in Bytes. Which is unused.
So we Have To Unzip it.....
Because Whenever we unzip it, then itself make one type of directory of sub directory and files So then we can access it in directory and file format.
While you can technically read the bytes from the zip archive without decompressing them, it will not help you as the data will be unusable in any epub display.
When a file is zipped, it is compressed using compression tables. This alters the data of the file, and to get back the original data you must decompress, or unzip, it first.
This is virtually no way to access files without unzipping. However, there is a way for targeted unzipping, i.e. unzipping a specific file instead of entire zipped folder. If that sounds good, you could probably go for Objective zip project.
P.S: Even i was working on a epub3 reader and I had to unzip the entire folder. Let me know if you find a better work around.

Keeping a text file in android

I am new to android and facing issue with file system usages.
I have seen several threads but i am still not able to find the answer which i am looking for my requirement.
I have a original file say test.xml which i want to keep somewhere in my eclipse project so that as soon as i install the app it should move my test.xml file into data directory so that i would be able to read it
please refere this link :
http://developer.android.com/training/basics/data-storage/files.html
I want to save my original file at : "/data/data/com.example.helloWorld/files"
I should be able to get the file handle form the below command
File file = new File(context.getFilesDir(), filename);
Please Note i dont want to save my file in asset folder.
Thanks,
Manish Bansal
I recommend you use assets as storage for your file initially as that will get compiled with your app, then once the user starts your app you check if your file exists and if not you can save the asset to the internal storage location as specified in the documentation, from there you can use the file as you like in the filesystem.

How to write to a file saved in local folder in Android

I am having a file in the folder res/raw/a.xml.
I want to write some data to this file?
How it can be done in Android?
How can we access a file stored in local directory in order to write data to that file.
can anyone help me in sorting out this issue ?
Thanks in Advance,
Hi, I am having a file in the folder res/raw/a.xml. I want to write some data to this file? How it can be done in Android?
You cannot modify a resource at runtime, sorry.
How can we access a file stored in local directory in order to write data to that file.
Use getFilesDir() to get a File object pointing to your app's local directory. Then, use standard Java I/O.

Categories

Resources