• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to use a local file to test a program

HeavensSentSword

Well-Known Member
Hello, I was wondering how to use a local file (i.e. something off you local disk drive C:) for testing purposes. I am working on understanding the URLConnection thing in android and want to try to bring a txt file in for processing, but I don't know how to because C: is not a valid html code. I also do not want to place the text file into the actual program because that would defeat the purpose of calling it in via URL.
Do I have to make a File file new File thing and read the outside file into that to do this?
thank you very much
 
Hi HeavensSentSword, If your purpose is to make an http call to get a file, it can be done by setting up a local website on your pc (you can use a program like XAMPP)

Once you create the local website, you can place the txt file under the web folder; to call it from your browser you should write "localhost/txtfile.txt" for example.
To call it form your app you must use the IP Address of your pc that has the local website on.
Example your pc has the IP 192.168.1.100 and you placed the file in the root folder of the website, the url that must be called from the app will be http:192.168.1.100/name_of_file.txt

I have tried and it worked for me with no issues.
I created a local web site on my pc, then made a test app in which I called the txt file using the url written before.

Hope you understand what I wrote, my english is not so good.
 
Back
Top Bottom