List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:Main.java
/** * * @param path/*from w w w . j av a 2s. c om*/ * @return */ public static Bitmap returnBmpByPath(String path) { Bitmap bitmap = null; File file = new File(path); try { if (file.exists()) { FileInputStream is = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(is); is.close(); } } catch (IOException e) { e.printStackTrace(); } //Log.v(tag, bitmap.toString()); return bitmap; }
From source file:Main.java
public static byte[] readBytesFromFile(File file) { if (file != null && file.exists() && file.isFile()) { int filelength = (int) file.length(); byte[] filecontent = new byte[filelength]; try {//w w w .j a v a 2 s . co m FileInputStream in = new FileInputStream(file); in.read(filecontent); in.close(); } catch (Exception e) { Log.v(TAG, "read file is error"); return null; } return filecontent; } return null; }
From source file:Main.java
public static String encodeBase64File(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);// ww w . ja v a2 s. c o m inputFile.close(); return android.util.Base64.encodeToString(buffer, Base64.DEFAULT); }
From source file:Main.java
/** * This method reads an XML file and returns its contents as String. * @param xmlFileName The name (path) of the XML file. * @return The string (XML) representation of the XML file. * @throws Exception If there is a problem. *//* www. j av a2 s. com*/ public static String convertXmlToString(String xmlFileName) throws Exception { File file = new File(xmlFileName); FileInputStream insr = new FileInputStream(file); byte[] fileBuffer = new byte[(int) file.length()]; insr.read(fileBuffer); insr.close(); return new String(fileBuffer); }
From source file:Main.java
public static String FiletoBase64(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);/* w ww .ja v a 2s.com*/ inputFile.close(); return new String(Base64.encodeBase64(buffer)); }
From source file:Main.java
public static String encodeBase64File(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);/*from w ww . j a v a 2 s . c o m*/ inputFile.close(); return Base64.encodeToString(buffer, Base64.DEFAULT); }
From source file:Main.java
public static byte[] getBytesFromFile(String path) throws IOException { FileInputStream file = new FileInputStream(path); byte[] data = new byte[(int) file.available()]; file.read(data);//from www . java 2 s. c o m file.close(); return data; }
From source file:Main.java
public static Bitmap decodeFile(File f, int maxSize) { Bitmap b = null;/*w w w . j a v a 2 s . co m*/ try { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > maxSize || o.outWidth > maxSize) { scale = (int) Math.pow(2, (int) Math .round(Math.log(maxSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return b; }
From source file:Main.java
public static byte[] readBytesFromFile(String path) { if (path == null || path.trim().length() == 0) { return null; }//from w ww. ja v a 2s . c o m File file = new File(path); if (file.exists() && file.isFile()) { int filelength = (int) file.length(); byte[] filecontent = new byte[filelength]; try { FileInputStream in = new FileInputStream(file); in.read(filecontent); in.close(); } catch (IOException e) { Log.v(TAG, "read file is error"); return null; } return filecontent; } return null; }
From source file:Main.java
public static Bitmap readBitmapFile(String aFileName) { Bitmap bitmap = null;/*w w w. j a v a 2s. c o m*/ File file = new File(aFileName); try { FileInputStream fis = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fis); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }