Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.InputStream; import java.io.RandomAccessFile; public class Main { public static void readStreamToFile(InputStream inStream, String filePath) throws Exception { File file = new File(filePath + ".wei"); RandomAccessFile outStream = new RandomAccessFile(file, "rw"); outStream.seek(0); byte[] buffer = new byte[1024]; int len = -1; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.close(); inStream.close(); file.renameTo(new File(filePath)); return; } }