import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
public class IOUtil {
public static byte[] file2ByteArray(String fpath){
InputStream is = null;
byte[] data = null;
try {
is = new FileInputStream(fpath);
data = IOUtils.toByteArray(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null)is.close();
} catch (IOException e) {
}
}
return data;
}
public static String byteArray2File(byte[] byteArray, String fpath){
File file = new File(fpath);
OutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(byteArray);
os.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (os != null)
os.close();
} catch (IOException e) {
}
}
return fpath;
}
}