@@ -0,0 +1,1849 @@
+package com.chess.genesis;%0A%0Aimport android.net.Uri;%0Aimport android.os.Environment;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.nio.channels.FileChannel;%0Aimport java.nio.charset.Charset;%0Aimport java.nio.MappedByteBuffer;%0A%0Aclass FileUtils%0A%7B%0A%09private static FileInputStream tryOpenFileStream(final String path) throws FileNotFoundException%0A%09%7B%0A%09%09FileInputStream file = null;%0A%09%09boolean error = false;%0A%09%09String p = new String(path);%0A%0A%09%09while (p.length() %3E 0) %7B%0A%09%09%09try %7B%0A%09%09%09%09file = new FileInputStream(p);%0A%09%09%09%7D catch (FileNotFoundException e) %7B%0A%09%09%09%09error = true;%0A%0A%09%09%09%09final int i = p.indexOf('/', 1);%0A%09%09%09%09if (i == -1)%0A%09%09%09%09%09p = new String();%0A%09%09%09%09else%0A%09%09%09%09%09p = p.substring(i);%0A%09%09%09%7D%0A%09%09%09if (!error)%0A%09%09%09%09return file;%0A%09%09%09error = false;%0A%09%09%7D%0A%09%09throw new FileNotFoundException();%0A%09%7D%0A%0A%09public static String readFile(final String path) throws FileNotFoundException, IOException%0A%09%7B%0A%09%09final FileInputStream stream = tryOpenFileStream(path);%0A%0A%09try %7B%0A%09%09final FileChannel fc = stream.getChannel();%0A%09%09final MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());%0A%0A%09%09/* Instead of using default, pass in a decoder. */%0A%09%09return Charset.defaultCharset().decode(bb).toString();%0A%09%7D finally %7B%0A%09%09stream.close();%0A%09%7D%0A%09%7D%0A%0A%09public static Uri writeFile(final String filename, final String data) throws FileNotFoundException, IOException%0A%09%7B%0A%09%09final String state = Environment.getExternalStorageState();%0A%0A%09%09if (!Environment.MEDIA_MOUNTED.equals(state))%0A%09%09%09throw new FileNotFoundException();%0A%0A%09%09final File dir = Environment.getExternalStorageDirectory();%0A%09%09final File file = new File(dir, filename);%0A%09%09final FileOutputStream buffer = new FileOutputStream(file);%0A%0A%09%09buffer.write(data.getBytes());%0A%09%09buffer.close();%0A%0A%09%09return Uri.fromFile(file);%0A%09%7D%0A%7D%0A

add FileUtils class for reading/writting files