Java tutorial
/* Copyright 2012 Mikhail Chabanov Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package mc.lib.files; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import mc.lib.image.ImageHelper; import mc.lib.stream.StreamHelper; import org.json.JSONObject; import org.w3c.dom.Document; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.util.Log; public class FileReadingHelper { private static String LOGTAG = FileReadingHelper.class.getSimpleName(); public static String readText(String filePath) { return readText(new File(filePath)); } public static String readText(File file) { FileInputStream is = null; try { is = new FileInputStream(file); return StreamHelper.readStream(is); } catch (FileNotFoundException e) { Log.e(LOGTAG, "Cannot read file " + file.getAbsoluteFile(), e); } finally { StreamHelper.close(is); } return null; } public static Bitmap readBitmap(Context context, String filePath) { return readBitmap(context, new File(filePath)); } public static Bitmap readBitmap(Context context, File file) { return ImageHelper.getBitmap(context, file); } public static Drawable readDrawable(Context context, String filePath) { return readDrawable(context, new File(filePath)); } public static Drawable readDrawable(Context context, File file) { return ImageHelper.bitmapToDrawable(readBitmap(context, file)); } public static Document readXml(String filePath) { return readXml(new File(filePath)); } public static Document readXml(File file) { return null; } public static JSONObject readJson(String filePath) { return readJson(new File(filePath)); } public static JSONObject readJson(File file) { return null; } }