Java tutorial
//package com.java2s; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public final static String PHONE_BASE_PATH = "sdcard/TestResult_nimh/"; public static void writeToFile(String fileName, String toWrite) throws IOException { File dir = new File(PHONE_BASE_PATH); if (!dir.exists()) { dir.mkdirs(); } File f = new File(PHONE_BASE_PATH, fileName); FileWriter fw = new FileWriter(f, true); fw.write(toWrite + '\n'); fw.flush(); fw.close(); f = null; } }