Skip to content

Commit

Permalink
尽量再兼容一下Java7
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZMarquis committed Nov 12, 2023
1 parent 4b6cc41 commit 3ccaf22
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/test/java/org/zz/gmhelper/test/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@

public class FileUtil {
public static void writeFile(String filePath, byte[] data) throws IOException {
try (RandomAccessFile raf = new RandomAccessFile(filePath, "rw")) {
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 (RandomAccessFile raf = new RandomAccessFile(filePath, "r")) {
try {
raf = new RandomAccessFile(filePath, "r");
data = new byte[(int) raf.length()];
raf.read(data);
return data;
} finally {
if (raf != null) {
raf.close();
}
}
}
}

0 comments on commit 3ccaf22

Please sign in to comment.