List of usage examples for java.io FileInputStream available
public int available() throws IOException
From source file:Main.java
/** * <pre>/*from w ww .j a va 2s. com*/ * Read binary data from arbitrary file. * </pre> * @param absolutePath absolute path to source file * @return binary data */ public static byte[] readFile(String absolutePath) throws IOException { File file = new File(absolutePath); if (!file.exists()) { return null; } FileInputStream in = new FileInputStream(file); byte[] b = new byte[in.available()]; in.read(b); in.close(); return b; }
From source file:Main.java
public static long getFileSize(File file) { long s = 0;// ww w . ja va 2 s.c o m if (file != null && file.exists()) { FileInputStream fis = null; try { fis = new FileInputStream(file); s = fis.available(); } catch (FileNotFoundException e) { } catch (IOException e) { } } return s; }
From source file:com.kyon.klib.base.KFileUtils.java
public static String readFile(Context context, String fileName) throws IOException { String res = ""; try {/*from w w w. j a v a2 s .c om*/ FileInputStream fIn = context.openFileInput(fileName); int length = fIn.available(); byte[] buffer = new byte[length]; fIn.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fIn.close(); } catch (Exception e) { e.printStackTrace(); } return res; }
From source file:Main.java
public static long getFileSizes(File f) { FileInputStream fis = null; try {/*from ww w . j a v a 2 s. c o m*/ fis = new FileInputStream(f); return fis.available(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (fis != null) fis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return -1; }
From source file:org.apache.drill.exec.store.http.util.JsonConverter.java
@SuppressWarnings("resource") public static String stringFromFile(String file) { try {//ww w . j av a 2 s. com FileInputStream stream = new FileInputStream(file); int size = stream.available(); byte[] bytes = new byte[size]; stream.read(bytes); return new String(bytes, Charsets.UTF_8); } catch (IOException e) { } return ""; }
From source file:Main.java
public static byte[] read(Context context, String fileName) throws FileNotFoundException, IOException { File file = getFile(context, fileName); ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (file != null) { FileInputStream fis = new FileInputStream(file); byte[] data = new byte[fis.available()]; fis.read(data);/*from ww w. j a v a 2s .com*/ bos.write(data); fis.close(); } return bos.toByteArray(); }
From source file:Main.java
public static byte[] getFileContent(String fileName) { FileInputStream fin = null; try {//from ww w .j a va 2 s .com fin = new FileInputStream(fileName); int length = fin.available(); byte[] bytes = new byte[length]; fin.read(bytes); return bytes; } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (fin != null) { fin.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.chargebee.MethodBank.MethodBank.java
public static JSONObject readJsonObjectData(String fileName) throws Exception { //processes the Json object and returns in the required format. File f = new File(fileName); FileInputStream fr = new FileInputStream(f); byte[] b = new byte[fr.available()]; fr.read(b);/*from www . ja va 2 s .c o m*/ JSONObject jobj = new JSONObject(new String(b)); return jobj; // The required Json object }
From source file:com.chargebee.MethodBank.MethodBank.java
public static JSONArray readJsonArrayData(String fileName) throws Exception { //processes the Json array and returns in the required format. File f = new File(fileName); FileInputStream fr = new FileInputStream(f); byte[] b = new byte[fr.available()]; fr.read(b);/*from w w w. java2s. com*/ JSONArray jarr = new JSONArray(new String(b)); return jarr; // The required Json array }
From source file:net.itransformers.bgpPeeringMap.BgpPeeringMapFromFile.java
private static byte[] readRawDataFile(String rawData) throws Exception { FileInputStream is = new FileInputStream(rawData); byte[] data = new byte[is.available()]; is.read(data);//from ww w . j a v a 2 s . c o m return data; }