U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

How to create text file and insert data to that file on Android

How to create text file and insert data to that file on Android

Question :

How might I make file.txt and embed information on document with substance of some of variable on my code for instance : populace [][]; on Android, so there will be envelope records on our bundle in record voyager (infos/infos/package/docs/ourfiles.txt) Thank You.

Solutions:

Every app project must have an AndroidManifest.xml file (with precisely that name) at the root of the project source setThe manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
permission in the Android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This is the code :
public void generateNoteOnSD(Context context, String sFileName, String sBody) {
    try {
        File root = new File(Environment.getExternalStorageDirectory(), "Notes");
        if (!root.exists()) {
            root.mkdirs();
        }
        File gpxfile = new File(root, sFileName);
        FileWriter writer = new FileWriter(gpxfile);
        writer.append(sBody);
        writer.flush();
        writer.close();
        Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
if you want to improve the solution,
comment to help the community

Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage