List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:Main.java
public static byte[] readBytes(String file) { try {//from w w w . j a v a 2 s . co m FileInputStream fis = new FileInputStream(file); int len = fis.available(); byte[] buffer = new byte[len]; fis.read(buffer); fis.close(); return buffer; } catch (Exception e) { System.out.println(e.getMessage()); } return null; }
From source file:Main.java
static String File2String(String path) { String strReturn = ""; try {// w w w. j ava2s . com File f = new File(path); FileInputStream fis = new FileInputStream(f); byte[] bDoc = new byte[fis.available()]; fis.read(bDoc); strReturn = new String(bDoc); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return strReturn; }
From source file:Main.java
public static String peekValue(final File file, final String xpathExpression) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { final DocumentBuilder db = DBF.newDocumentBuilder(); final FileInputStream fis = new FileInputStream(file); final Document doc; try {/* ww w .j a v a2 s . c o m*/ doc = db.parse(fis); } finally { fis.close(); } final String result = peekValue(doc, xpathExpression); return result; }
From source file:PropertiesUtils.java
/** * Loads properties by given file// w w w . j a va 2 s .co m * * @param file * filename * @return loaded properties * @throws java.io.IOException * if can't load file */ public static Properties load(File file) throws IOException { FileInputStream fis = new FileInputStream(file); Properties p = new Properties(); p.load(fis); fis.close(); return p; }
From source file:Main.java
public static Object readFileByObject(String fileName) { try {/* w ww .j av a2s . c o m*/ FileInputStream fis = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(fis); Object o = ois.readObject(); ois.close(); fis.close(); return o; } catch (Exception e) { return null; } }
From source file:com.ewcms.common.io.HtmlFileUtil.java
public static byte[] readByte(File f) { try {/*from w ww .jav a 2s. c om*/ f = normalizeFile(f); FileInputStream fis = new FileInputStream(f); byte r[] = readByte(((InputStream) (fis))); fis.close(); return r; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:UtilFunctions.java
public static String makeHash(File file) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(file); String hash = DigestUtils.md5Hex(fis); fis.close(); return hash;//from w w w .java 2 s . co m }
From source file:net.ontopia.utils.EncryptionUtils.java
/** * INTERNAL: Reads in the infile and writes the encrypted result * into the outfile.// w ww . j ava 2 s .c o m */ public static void encrypt(File infile, File outfile) throws IOException { FileInputStream in = new FileInputStream(infile); FileOutputStream out = new FileOutputStream(outfile); encrypt(in, out); in.close(); out.close(); }
From source file:common.DBTestUtil.java
public static void initDB() throws IOException, SQLException { String query = ""; FileInputStream inputStream = new FileInputStream(TEST_DATA_FILE); try {/*from www .ja v a 2 s. co m*/ query = IOUtils.toString(inputStream); } finally { inputStream.close(); } Connection connection = DB.getConnection(); try { Statement statement = connection.createStatement(); statement.execute(query); } finally { connection.close(); } }
From source file:Main.java
/** * //from w ww . j ava 2 s . com * @param file */ public static void decodeFile(File file) { Bitmap bitmap = null; try { // Decode image size BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; FileInputStream fileInputStream = new FileInputStream(file); BitmapFactory.decodeStream(fileInputStream, null, options); fileInputStream.close(); int scale = 1; if (options.outHeight > 500 || options.outWidth > 500) { scale = (int) Math.pow(2, (int) Math.round( Math.log(500 / (double) Math.max(options.outHeight, options.outWidth)) / Math.log(0.5))); } // Decode with inSampleSize BitmapFactory.Options options2 = new BitmapFactory.Options(); options2.inSampleSize = scale; fileInputStream = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fileInputStream, null, options2); fileInputStream.close(); FileOutputStream output = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, output); output.flush(); output.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }