📄 keycipher.java
字号:
package src;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class KeyCipher {
private static byte[] key;
public static byte[] readFile(String filename) throws Exception {
try {
File f = new File(filename);
FileInputStream fs = new FileInputStream(f);
FileChannel fc = fs.getChannel();
int size = (int) fc.size();
ByteBuffer buffer = ByteBuffer.allocateDirect(size);
fc.read(buffer);
buffer.flip();
byte[] byteArray = new byte[size];
buffer.get(byteArray);
buffer.clear();
fc.close();
fs.close();
return byteArray;
} catch (Exception e) {
throw new Exception("File not found!");
}
}
public static void writeFile(String filename, byte[] byteArray)
throws Exception {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filename);
fos.write(byteArray);
fos.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException iex) {
}
}
}
public static void saveKey(String filename, byte[] key) throws Exception {
writeFile(filename, key);
}
public static byte[] loadKey(String filename) throws Exception {
key = readFile(filename);
return key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -