List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:com.google.orkut.client.api.Util.java
/** Load a file and returns its content as a byte array. * * @param fileName the name of the file to load. * @return The full contents of the file as a byte array. */ public static byte[] loadFile(String fileName) throws java.io.IOException { java.io.FileInputStream fin = new java.io.FileInputStream(fileName); byte[] b = readAllFrom(fin); fin.close(); return b;/*from w w w . j ava2 s. c om*/ }
From source file:Main.java
/** * Read the original picture to an array * /*w w w . j ava2 s.c o m*/ * @param initialFile * @param size * @return an array with the address and values */ public static int[] readBaseFile(String initialFile, int size) { int[] imageTxt = new int[size]; FileInputStream fin; try { // Open an input stream fin = new FileInputStream(initialFile); int k = 0; while (fin.available() != 0) { imageTxt[k++] = fin.read(); } fin.close(); } // Catches any error conditions catch (IOException e) { System.err.println("Unable to read image"); System.exit(1); } return imageTxt; }
From source file:Main.java
public static String[] GetSupportedFileSystems() { try {// w w w. ja va 2 s . co m FileInputStream fProcFS = new FileInputStream(new File("/proc/filesystems")); ArrayList<String> filesystems = new ArrayList<String>(); byte[] data1 = new byte[1024]; int len = fProcFS.read(data1); fProcFS.close(); String fs = new String(data1, 0, len); if (fs.contains("rfs")) filesystems.add("rfs"); if (fs.contains("jfs")) filesystems.add("jfs"); if (fs.contains("ext2")) filesystems.add("ext2"); if (fs.contains("ext3")) filesystems.add("ext3"); if (fs.contains("ext4")) filesystems.add("ext4"); String[] List = (String[]) filesystems.toArray(new String[filesystems.size()]); return List; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.eel.kitchen.jsonschema.util.JsonLoader.java
/** * Same as {@link #fromPath(String)}, but this time the user supplies the * {@link File} object instead/*from ww w.ja v a 2s . c o m*/ * * @param file the File object * @return The document * @throws IOException in many cases! */ public static JsonNode fromFile(final File file) throws IOException { final JsonNode ret; final FileInputStream in = new FileInputStream(file); try { ret = mapper.readTree(in); } finally { in.close(); } return ret; }
From source file:org.eel.kitchen.jsonschema.util.JsonLoader.java
/** * Read a {@link JsonNode} from a file on the local filesystem. * * @param path the path (relative or absolute) to the file * @return the document in the file//from ww w. j av a 2s . c o m * @throws IOException if this is not a file, if it cannot be read, etc. */ public static JsonNode fromPath(final String path) throws IOException { final JsonNode ret; final FileInputStream in = new FileInputStream(path); try { ret = mapper.readTree(in); } finally { in.close(); } return ret; }
From source file:ca.tbcn.greenp.GreenParkingApp.java
/** * Load json from stored file, create file if it's not there * //from w w w . j a v a2 s.c o m * @param context * @return * @throws IOException */ public static String getJsonFileContents(Context context) throws IOException { if (!Util.fileExists(context, JSON_FILE_NAME)) { seedJsonFile(context); } FileInputStream fis = context.openFileInput(JSON_FILE_NAME); String contents = Util.inputStreamToString(fis); fis.close(); return contents; }
From source file:com.kyon.klib.base.KFileUtils.java
public static String readFile(Context context, String fileName) throws IOException { String res = ""; try {/*w ww. ja va2 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:heigit.ors.util.FileUtility.java
public static String readFile(File file, int bufferSize) throws IOException { FileInputStream fis = new FileInputStream(file); String result = StreamUtility.readStream(fis); fis.close(); return result; }
From source file:heigit.ors.util.FileUtility.java
public static String readFile(String fileName, int bufferSize) throws IOException { File file = new File(fileName); FileInputStream fis = new FileInputStream(file); String result = StreamUtility.readStream(fis); fis.close(); return result; }
From source file:Main.java
public static Point getBitmapSize(String filepath) { File f = new File(filepath); Point p = null;/* w w w . j av a 2s.c o m*/ FileInputStream fs = null; try { fs = new FileInputStream(f); p = getBitmapSize(fs); } catch (FileNotFoundException e) { } finally { if (fs != null) { try { fs.close(); } catch (IOException e) { } } } return p; }