List of usage examples for java.io FileOutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this file output stream. From source file:Main.java
public static File downloadFile(String urlstr, File saveFile) { try {/*from ww w .j a v a2 s. co m*/ URL url = new URL(urlstr);// cause speed low. URLConnection con = url.openConnection(); con.setDoInput(true); con.connect(); InputStream ins = con.getInputStream(); final int bufsize = 102400; byte[] buffer = new byte[bufsize]; int len = -1; FileOutputStream bos = new FileOutputStream(saveFile); while ((len = ins.read(buffer)) != -1) { bos.write(buffer, 0, len); } ins.close(); bos.close(); return saveFile; } catch (Error e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
@Deprecated private static void copy(InputStream in, File dst) throws IOException { FileOutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len;//from w w w . j a v a2 s .c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static void copyFileFromAssets(Context context, String fileName, File outputFile) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesCount; try {/*from w w w . java 2 s . c om*/ InputStream imageStream = context.getAssets().open(fileName); FileOutputStream fileOutputStream = new FileOutputStream(outputFile); while ((bytesCount = imageStream.read(buffer)) >= 0) { fileOutputStream.write(buffer, 0, bytesCount); } fileOutputStream.close(); imageStream.close(); } catch (IOException | Resources.NotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean writeFile(String to, String value) { boolean result = false; FileOutputStream out = null; try {/*from w w w . jav a 2 s . co m*/ out = new FileOutputStream(to); byte[] buffer = value.getBytes(); out.write(buffer, 0, value.length()); out.flush(); result = true; } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } return result; }
From source file:Main.java
private static long copyLarge(InputStream input, File outputFile) throws IOException { byte[] buffer = new byte[16384]; long count = 0; int n = 0;/*from w w w. j a v a 2 s. c o m*/ outputFile.getParentFile().mkdirs(); FileOutputStream output = new FileOutputStream(outputFile); try { while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } } finally { output.close(); } return count; }
From source file:Main.java
private static void saveStream(InputStream is, String savePath) throws IOException { FileOutputStream output = new FileOutputStream(savePath); int readlen;//from w w w .j a v a2 s . co m byte[] buf = new byte[BUFF_SIZE]; while ((readlen = is.read(buf)) > 0) { output.write(buf, 0, readlen); } output.close(); }
From source file:Main.java
public static void readAsFile(InputStream inSream, File file) throws Exception { FileOutputStream outStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = -1; while ((len = inSream.read(buffer)) != -1) { outStream.write(buffer, 0, len); }/*from w w w . j a va 2 s. c o m*/ outStream.close(); inSream.close(); }
From source file:Main.java
public static void copyFile(FileInputStream src, FileOutputStream dst) throws Throwable { byte[] buf = new byte[65536]; for (int len = src.read(buf); len > 0; len = src.read(buf)) { dst.write(buf, 0, len); }//from www . j a v a2s . co m src.close(); dst.close(); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.log.ProblemsDatabaseUpdateJobTest.java
private static void createEmptyZip(File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); fos.write(MINIMAL_ZIP_FILE, 0, 22); fos.flush();//from www .j a v a2 s .c o m fos.close(); }
From source file:Main.java
private static void writeToOutFile(File toFile, FileInputStream fosfrom) throws IOException { FileOutputStream fosto = null; fosto = new FileOutputStream(toFile); byte bt[] = new byte[1024]; int c;//from w ww . j a v a 2 s .com while ((c = fosfrom.read(bt)) > 0) { fosto.write(bt, 0, c); } fosto.close(); }