java ByteBuffer写入文件的字符集问题
有一种方法可以对文件进行编码java ByteBuffer写入文件的字符集问题,java,character-encoding,nio,Java,Character Encoding,Nio,有一种方法可以对文件进行编码 public static void cipher(File input, int[] key, File output) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(10); FileInputStream fin = new FileInputStream(input); FileChannel fcin = fin.getChannel(); Fi
public static void cipher(File input, int[] key, File output) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(10);
FileInputStream fin = new FileInputStream(input);
FileChannel fcin = fin.getChannel();
FileOutputStream fout = new FileOutputStream( output );
FileChannel fcout = fout.getChannel();
ByteBuffer temp;
while (true){
buffer.clear();
int r = fcin.read(buffer);
if(r == -1){
break;
}
//cb = StandardCharsets.UTF_8.decode(cipherBuffer(buffer,key));
//System.out.println(cb.toString());
temp = cipherBuffer(buffer,key);
for (int i = 0; i < 10; i++){
System.out.print((char)temp.get(i));
}
temp.flip();
fcout.write(temp);
}
}
这就是这个阶段的输出情况
ᄚᄎᄋᄏᄚᄇタ ᄒᄈムᄒᄡ ᄉテᄒᄏ
使用cipherBuffer()实现测试它,只返回输入。一切正常。cipherBuffer()方法中可能存在问题。cipherBuffer方法非常原始,不要认为它工作不正常,因为您认为它与此无关。如果你认为是正确的,你的代码就会工作;你不会有问题;您不会在这里发布。您使用的是什么输入文件,预期的输出是什么?我希望看到相同的文本,但根据给定的键,每10个符号将混合一次
ᄚᄎᄋᄏᄚᄇタ ᄒᄈムᄒᄡ ᄉテᄒᄏ