?? 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 + -