Can .txt file be retrieved to textview from parse.com - android

Can I add .txt file in parse.com and retrieve it to my textview in my app. I know how to add a string and retrieve it but have a confusion regarding the .Txt file

When your creating your ParseFile object, you can give it a file type by adding the file extension to the end of the key name.
Eg:
ParseFile file = new ParseFile("sometext.txt", fileData);
will create a text file the the contents of fileData. This can be attached to a ParseObject and saved/retrieved from Parse the usual way.
By the way, you should give this question a parse.com tag.

Related

Reading JSON or text file in resource folder

I am developing Kotlin app.
I am trying to read text and JSON files which I stored in resource folder(res/raw/file.txt).
Looking at the hierachy of app structure, I put absolute path(../../res/raw/file.txt) for file reader.
Unfortunately, my app cannot find the file.
Can you tell me how I can read files stored in res/raw? If I store file in wrong directory, can you tell me where to store and how to access them?
Thanks
If you want to read a file from res/raw folder you can obtain InputStream by R.raw.yourfile id like this:
resources.openRawResource(R.raw.yourfile)
Or you can open file by Uri:
val uri = Uri.parse("android.resource://com.example.your_package/raw/yourfile")
val file = File(uri.getPath());
Alternatevily you can put your files in assets/ folder and get InputStream like this:
assets.open("yourfile.txt")

Show all .txt files from a folder in an activity

I have a application where the user can write a text into a EditText and the written text is saved in an auto generated .txt file.
Now I want to show all the txt files from the folder in an activity, not like a regular file browser, just the title of the .txt files in a ListView or as a TextView (each file is illustrated as a TextView).
Get the path of that directory as string and create a new file with this path then,
String path=Environment.getExternalStorageDirectory().getAbsolutePath()+"..../yourFolder";
File file=new File(path);
or
File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"..../yourFolder");
Use file.list which will give u all files name in form of an array then use a for loop with endsWith function and store data into a list like this
String arr[]=file.list();
List l=new ArrayList<>();
for(String i:arr){
if(i.endsWith(".txt")){
l.add(i);
}
}
you will have names all text files under selected directory in list l
In Java 8 you can use Files API and Stream API
Files
.list(Paths.get("."))
.forEach(System.out::println);

Can't read file stored in res/raw

I'm unable to successfully get the contents of a public key file that I have stored in my res/raw directory.
My objective is to read the contents of this file into a File object that I will then pass along to another function that requires a File object as one of its parameters.
It's important to note that this file contains an X509 key, which I believe means that I need to read its contents as bytes (not text).
This is in the onCreate method of my main activity:
String filename = context.getResources().getResourceName(R.raw.public_key);
Log.d(TAG, filename);
File publicKeyFile = new File(filename);
if (!publicKeyFile.exists()) Log.d(TAG, "no public key file");
Which yields this output:
raw/public_keyno public key file
What am I doing wrong? Thanks!
My objective is to read the contents of this file into a File object that I will then pass along to another function that requires a File object as one of its parameters.
That is not possible, unless you make your own local copy of that file.
What am I doing wrong?
Raw resources are not files. They are entries in the ZIP archive that is the APK file. If you want a File, open an InputStream on the raw resource, copy its contents out to a local file, then use the local file.

How to read data from xml file which is stored insdcard?

I am trying to read data from an xml which is stored at sdcard.
So, I used XmlResourceParser in my code but how can I provide my xml file to XmlResourceParser?
Is there any other way to do the same?
File myXmlFile = new File(Environment.getExternalStorageDirectory()+"/myfiles/myxml.xml");
And try to read data from File...

How To Extract XML Strings From an Android App's Data

I have an app that pulls an XML file from a URL and saves it to its data/data/package.name/file.xml directory. All the XML is is strings. Say I want to reference the String named "restaurant1PhoneNumber". How do I extract it's string value in the XML file?

Categories

Resources