List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:net.firejack.platform.core.utils.SecurityHelper.java
public static byte[] read64(String name) throws IOException { File file = new File(name); FileInputStream stream = new FileInputStream(file); byte[] bytes = new byte[(int) file.length()]; stream.read(bytes);/* w w w . j a v a 2s . c o m*/ stream.close(); return Base64.decode(bytes); }
From source file:com.bahmanm.karun.Utils.java
/** * Copies srcPath to destPath./* w w w .j ava 2s. c om*/ * * @param srcPath Path to source file * @param destPath Path to destination file * @throws FileNotFoundException * @throws IOException */ public synchronized static void copyFile(String srcPath, String destPath) throws FileNotFoundException, IOException { FileInputStream in = new FileInputStream(srcPath); FileOutputStream out = new FileOutputStream(destPath); IOUtils.copy(in, out); in.close(); out.close(); }
From source file:Main.java
/** * Use the file and count the chars in the file, so we can use static arrays * /* w w w. j ava 2s. com*/ * @param fileName * @return integer with the size of the file */ public static int countBytes(String fileName) { FileInputStream fin; int charCount = 0; try { // Open an input stream fin = new FileInputStream(fileName); while (fin.available() != 0) { fin.read(); charCount++; } fin.close(); } // Catches any error conditions catch (IOException e) { System.err.println("Unable to read image"); System.exit(1); } return charCount; }
From source file:MainClass.java
public static void copy(String inFile, String outFile) throws IOException { FileInputStream fin = null; FileOutputStream fout = null; try {/* w ww . j av a2 s .c om*/ fin = new FileInputStream(inFile); fout = new FileOutputStream(outFile); copy(fin, fout); } finally { try { if (fin != null) fin.close(); } catch (IOException ex) { } try { if (fout != null) fout.close(); } catch (IOException ex) { } } }
From source file:controller.file.FileUploader.java
public static void fileDownloader(HttpServletRequest request, HttpServletResponse response) { PrintWriter out = null;/*from w ww. j av a2 s .co m*/ try { String filename = "foo.xml"; String filepath = "/tmp/"; out = response.getWriter(); response.setContentType("APPLICATION/OCTET-STREAM"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename); int i; while ((i = fileInputStream.read()) != -1) { out.write(i); } fileInputStream.close(); out.close(); } catch (IOException ex) { Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } }
From source file:pieShareAppITs.helper.ITUtil.java
public static boolean waitForFileToBeFreed(File file, int sec) { boolean done = false; int time = 0; //todo: this has to move to utils: this is a check if the access to the file has been restored //after torrent work while (!done || time >= sec) { try {//from w w w. java 2 s . c o m Thread.sleep(1000); FileInputStream st = new FileInputStream(file); done = true; st.close(); return true; } catch (FileNotFoundException ex) { //nothing needed to do here } catch (IOException ex) { //nothing needed to do here } catch (InterruptedException ex) { //nothing needed to do here } } return false; }
From source file:cz.zcu.kiv.eegdatabase.wui.components.utils.FileUtils.java
/** * Prepare byte array from file./*from ww w . ja v a 2 s .com*/ * * @param file * @return */ public static byte[] getFileContent(File file) { if (file == null) { return new byte[0]; } else { try { FileInputStream fileInputStream = new FileInputStream(file); byte[] byteArray = IOUtils.toByteArray(fileInputStream); fileInputStream.close(); return byteArray; } catch (FileNotFoundException e) { log.error(e.getMessage(), e); return new byte[0]; } catch (IOException e) { log.error(e.getMessage(), e); return new byte[0]; } } }
From source file:SwingResourceManager.java
/** * Returns an image stored in the file at the specified path * @param section String The storage section in the cache * @param path String The path to the image file * @return Image The image stored in the file at the specified path *//* www . j av a 2s .c om*/ public static Image getImage(String section, String path) { String key = section + '|' + SwingResourceManager.class.getName() + '|' + path; Image image = m_ClassImageMap.get(key); if (image == null) { try { FileInputStream fis = new FileInputStream(path); image = getImage(fis); m_ClassImageMap.put(key, image); fis.close(); } catch (IOException e) { return null; } } return image; }
From source file:Main.java
/** * Copy a file from one place to another *///from ww w . j a v a 2 s . co m private static void copyFile(File in, File out) throws Exception { FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out); try { copyStream(fis, fos); } catch (Exception e) { throw e; } finally { fis.close(); fos.close(); } }
From source file:Main.java
public static void copy(File src, File dst) throws IOException { FileInputStream inStream = new FileInputStream(src); FileOutputStream outStream = new FileOutputStream(dst); FileChannel inChannel = inStream.getChannel(); FileChannel outChannel = outStream.getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); inStream.close(); outStream.close();//from w w w . j a v a 2 s. c o m }