mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
34 lines
845 B
Java
34 lines
845 B
Java
package util;
|
|
|
|
import java.io.IOException;
|
|
import java.io.RandomAccessFile;
|
|
|
|
public class FileUtil {
|
|
public static void writeFile(String filePath, byte[] data) throws IOException {
|
|
RandomAccessFile raf = null;
|
|
try {
|
|
raf = new RandomAccessFile(filePath, "rw");
|
|
raf.write(data);
|
|
} finally {
|
|
if (raf != null) {
|
|
raf.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static byte[] readFile(String filePath) throws IOException {
|
|
RandomAccessFile raf = null;
|
|
byte[] data;
|
|
try {
|
|
raf = new RandomAccessFile(filePath, "r");
|
|
data = new byte[(int) raf.length()];
|
|
raf.read(data);
|
|
return data;
|
|
} finally {
|
|
if (raf != null) {
|
|
raf.close();
|
|
}
|
|
}
|
|
}
|
|
}
|