public void copy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
File f = new File(getCacheDir()+"/m1.map"); if (!f.exists()) try { InputStream is = getAssets().open("m1.map"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); FileOutputStream fos = new FileOutputStream(f); fos.write(buffer); fos.close(); } catch (Exception e) { throw new RuntimeException(e); } mapView.setMapFile(f.getPath());
public static void cpdir(File src, File dest) throws BrutException { dest.mkdirs(); File[] files = src.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; File destFile = new File(dest.getPath() + File.separatorChar + file.getName()); if (file.isDirectory()) { cpdir(file, destFile); continue; } try { InputStream in = new FileInputStream(file); OutputStream out = new FileOutputStream(destFile); IOUtils.copy(in, out); in.close(); out.close(); } catch (IOException ex) { throw new BrutException("Could not copy file: " + file, ex); } } }
@Override public void write(OutputStream output) throws IOException { InputStream input = null; try { input = new FileInputStream(new File(configFileStr)); byte[] buf = new byte[1024]; int bytesRead; while ((bytesRead = input.read(buf)) > 0) { output.write(buf, 0, bytesRead); } } finally { if( input != null) { input.close(); } } } });
/** * get md5. * * @param file file source. * @return MD5 byte array. */ public static byte[] getMD5(File file) throws IOException { InputStream is = new FileInputStream(file); try { return getMD5(is); } finally { is.close(); } }
/** * {@inheritDoc} */ public Manifest getManifest() throws IOException { File file = new File(folder, JarFile.MANIFEST_NAME); if (file.exists()) { InputStream inputStream = new FileInputStream(file); try { return new Manifest(inputStream); } finally { inputStream.close(); } } else { return NO_MANIFEST; } }
static private void copy(InputStream in, File dst) throws IOException { FileOutputStream out=new FileOutputStream(dst); byte[] buf=new byte[1024]; int len; while ((len=in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } }
public static byte[] readFile(File in) throws IOException { InputStream is = new FileInputStream(in); byte[] xml = new byte[is.available()]; is.read(xml); is.close(); return xml; }
@Override public String saveStaticFile(InputStream fileStream, String fileName) throws IOException { try { //文件后缀 String suffix = fileName.contains(".") ? fileName.substring(fileName.lastIndexOf(".")) : ""; //以日期划分目录 String filePath = DateFormatter.toString(new Date(), "yyyyMMdd"); //创建目录 new File(getStaticFilePath() + "/" + filePath).mkdirs(); // 存储的文件名 String realFileName = System.nanoTime() + suffix; String fileAbsName = getStaticFilePath() + "/" + filePath + "/" + realFileName; try (FileOutputStream out = new FileOutputStream(fileAbsName)) { StreamUtils.copy(fileStream, out); } //响应上传成功的资源信息 return getStaticLocation() + filePath + "/" + realFileName; } finally { fileStream.close(); } }
private void addTestDex() throws IOException { //write test dex String dexMode = "jar"; if (config.mDexRaw) { dexMode = "raw"; } final InputStream is = DexDiffDecoder.class.getResourceAsStream("/" + TEST_DEX_NAME); String md5 = MD5.getMD5(is, 1024); is.close(); String meta = TEST_DEX_NAME + "," + "" + "," + md5 + "," + md5 + "," + 0 + "," + 0 + "," + 0 + "," + dexMode; File dest = new File(config.mTempResultDir + "/" + TEST_DEX_NAME); FileOperation.copyResourceUsingStream(TEST_DEX_NAME, dest); Logger.d("\nAdd test install result dex: %s, size:%d", dest.getAbsolutePath(), dest.length()); Logger.d("DexDecoder:write test dex meta file data: %s", meta); metaWriter.writeLineToInfoFile(meta); }
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException { try { InputStream in = clazz.getResourceAsStream(resourcePath); if (in == null) { throw new FileNotFoundException(resourcePath); } File fileOut = File.createTempFile(tmpPrefix, null); fileOut.deleteOnExit(); OutputStream out = new FileOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); return fileOut; } catch (IOException ex) { throw new BrutException("Could not extract resource: " + resourcePath, ex); } } }
@Override public void run() { try { try { byte[] buf = new byte[8192]; int len; while ((len = in.read(buf)) >= 0) out.write(buf, 0, len); } finally { // it doesn't make sense not to close InputStream that's already EOF-ed, // so there's no 'closeIn' flag. in.close(); if(closeOut) out.close(); } } catch (IOException e) { // TODO: what to do? } } }
InputStream is = entity.getContent(); String filePath = "sample.txt"; FileOutputStream fos = new FileOutputStream(new File(filePath)); int inByte; while((inByte = is.read()) != -1) fos.write(inByte); is.close(); fos.close();
private void writeZone(File outputDir, DateTimeZoneBuilder builder, DateTimeZone tz) throws IOException { if (ZoneInfoLogger.verbose()) { System.out.println("Writing " + tz.getID()); } File file = new File(outputDir, tz.getID()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } OutputStream out = new FileOutputStream(file); try { builder.writeTo(tz.getID(), out); } finally { out.close(); } // Test if it can be read back. InputStream in = new FileInputStream(file); DateTimeZone tz2 = DateTimeZoneBuilder.readFrom(in, tz.getID()); in.close(); if (!tz.equals(tz2)) { System.out.println("*e* Error in " + tz.getID() + ": Didn't read properly from file"); } }
/** * get md5. * * @param file file source. * @return MD5 byte array. */ public static byte[] getMD5(File file) throws IOException { InputStream is = new FileInputStream(file); try { return getMD5(is); } finally { is.close(); } }
/** * {@inheritDoc} */ public Resolution locate(String name) throws IOException { File file = new File(folder, name.replace('.', File.separatorChar) + CLASS_FILE_EXTENSION); if (file.exists()) { InputStream inputStream = new FileInputStream(file); try { return new Resolution.Explicit(StreamDrainer.DEFAULT.drain(inputStream)); } finally { inputStream.close(); } } else { return new Resolution.Illegal(name); } }