Android Open Source - GNE_Nepal_App file I O






From Project

Back to project page GNE_Nepal_App.

License

The source code is released under:

GNU General Public License

If you think the Android project GNE_Nepal_App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.yadaming.gne_nepal_app;
/*from   w  w w .  ja  v  a  2 s  . co m*/
import android.os.Environment;
import android.util.Log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/* Implementation
set filename to be passed to write
set file content with survey answers
fileIO fio = new fileIO();
call fio.write with the filename and content
 */
public class fileIO {
    public fileIO() {
    }

    public Boolean write(String filename, String filecontent) {
        try {
            //String filepath = Environment.getExternalStorageDirectory().getPath() + filename + ".txt";

            // Try getting the filepath of the downloads directory
            File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

            //File file = new File(filepath);
            String data_filename = filename + ".txt";
            File file = new File(path, data_filename);

            if (!file.exists())
            {
                // createNewFile returns a public boolean that we don't care about
                file.createNewFile();
            }

            // get the file to write to from the file path
            FileWriter filewriter = new FileWriter(file.getAbsoluteFile(), true);

            BufferedWriter bufferwriter = new BufferedWriter(filewriter);
            filecontent = filecontent+"\n";
            bufferwriter.append(filecontent);

            // close the buffer for the buffer writer
            // TODO do we need to close the file?
            bufferwriter.close();

            Log.d("Written Success", "Written Success");

            return true;

        } catch (IOException exception) {
            exception.printStackTrace();
            return false;
        }
    }
}




Java Source Code List

com.yadaming.gne_nepal_app.Alcohol.java
com.yadaming.gne_nepal_app.Calcium.java
com.yadaming.gne_nepal_app.Cooking.java
com.yadaming.gne_nepal_app.End.java
com.yadaming.gne_nepal_app.Folate.java
com.yadaming.gne_nepal_app.Hand.java
com.yadaming.gne_nepal_app.Hygiene.java
com.yadaming.gne_nepal_app.InitialActivity.java
com.yadaming.gne_nepal_app.Iodine.java
com.yadaming.gne_nepal_app.Iron.java
com.yadaming.gne_nepal_app.Rice_main_circled.java
com.yadaming.gne_nepal_app.Rice_none_circled.java
com.yadaming.gne_nepal_app.Rice_right_circled.java
com.yadaming.gne_nepal_app.ScoreKeeper.java
com.yadaming.gne_nepal_app.Slide12Activity.java
com.yadaming.gne_nepal_app.Slide14Activity.java
com.yadaming.gne_nepal_app.Slide15Activity.java
com.yadaming.gne_nepal_app.Slide16Activity.java
com.yadaming.gne_nepal_app.Slide17Activity.java
com.yadaming.gne_nepal_app.Slide18Activity.java
com.yadaming.gne_nepal_app.Slide19Activity.java
com.yadaming.gne_nepal_app.Slide20Activity.java
com.yadaming.gne_nepal_app.Slide22Activity.java
com.yadaming.gne_nepal_app.Slide24Activity.java
com.yadaming.gne_nepal_app.Slide25Activity.java
com.yadaming.gne_nepal_app.Slide26Activity.java
com.yadaming.gne_nepal_app.Slide27Activity.java
com.yadaming.gne_nepal_app.Slide28Activity.java
com.yadaming.gne_nepal_app.Slide29Activity.java
com.yadaming.gne_nepal_app.Slide2Activity.java
com.yadaming.gne_nepal_app.Slide30Activity.java
com.yadaming.gne_nepal_app.Slide3Activity.java
com.yadaming.gne_nepal_app.Slide4Activity.java
com.yadaming.gne_nepal_app.Slide5Activity.java
com.yadaming.gne_nepal_app.Slide6Activity.java
com.yadaming.gne_nepal_app.Slide7Activity.java
com.yadaming.gne_nepal_app.Slide8Activity.java
com.yadaming.gne_nepal_app.SnackFoodActivity.java
com.yadaming.gne_nepal_app.SoundModule.java
com.yadaming.gne_nepal_app.VitaminA.java
com.yadaming.gne_nepal_app.Vitamin.java
com.yadaming.gne_nepal_app.WhyBeNutritious.java
com.yadaming.gne_nepal_app.fileIO.java
com.yadaming.gne_nepal_app.testActivity.java