Java 将解密文本追加到JTextArea

Java 将解密文本追加到JTextArea,java,encryption,aes,fileinputstream,fileoutputstream,Java,Encryption,Aes,Fileinputstream,Fileoutputstream,问题:在JTextArea中追加加密文本 目标:尝试使用JFileCHooser调用“decrypt”方法获取所选文件,然后将输出返回到原始方法(decryptArea)。所有代码如下 问题:为什么这不起作用?我不明白,因为我们正在处理文件的,不应该通过解密文件并附加它。我有一个正常的方法,做完全相同的事情,除了不解密当然(正常的保存文件和打开文件方法),只是试图把碎片放在一起,这将是不幸的,不知道我做错了什么,然后结束重新设计时,没有必要 userFieled=JTextArea()*****

问题:在JTextArea中追加加密文本

目标:尝试使用JFileCHooser调用“decrypt”方法获取所选文件,然后将输出返回到原始方法(decryptArea)。所有代码如下

问题:为什么这不起作用?我不明白,因为我们正在处理文件的,不应该通过解密文件并附加它。我有一个正常的方法,做完全相同的事情,除了不解密当然(正常的保存文件和打开文件方法),只是试图把碎片放在一起,这将是不幸的,不知道我做错了什么,然后结束重新设计时,没有必要

userFieled=JTextArea()***********

private void decryptArea() throws Exception {
  JFileChooser fc = new JFileChooser();
  fc.setMultiSelectionEnabled(true);
  fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  int dialog = fc.showOpenDialog(null);

  if (dialog == JFileChooser.APPROVE_OPTION) {
    inputDec = fc.getSelectedFile();
    inputDec.getName();
    inputDec.getAbsoluteFile();
    inputDec = fc.getSelectedFile();

    userField.append("");
    System.out.println(" File: " + inputDec);




   File fd = new File (inputDec.getAbsoluteFile().getAbsolutePath());
     FileReader reader = new FileReader(fd);
     BufferedReader br = new BufferedReader(reader);
     userField.read(br,null);

     br.close();
     userField.requestFocus();


  // userField.append(inputDec);
    userField.requestFocus();

    System.out.println("Finished appending decrypted text:");
  }

}  
    });
//解密是在哪里进行的

public void decrypt(File inputFile, File outputFile, byte[] key) throws Exception {
       Cipher cipher = getCipherDecrypt(key);
       FileOutputStream fos = null;
       CipherInputStream cis = null;
       FileInputStream fis = null;
       try {
           fis = new FileInputStream(inputFile);
           cis = new CipherInputStream(fis, cipher);
           fos = new FileOutputStream(outputFile);
           byte[] data = new byte[1024];
           int read = cis.read(data);
           while (read != -1) {
           fos.write(data, 0, read);
           read = cis.read(data);
           System.out.println(new String(data, "UTF-8").trim());
           }
       } finally {
           cis.close();
           fos.close();
           fis.close();
       }
}

什么是
userField
?您实际读取了该文件吗?如中所示,是否将其加载到内存中?如果是,在哪里?从我的观点来看,我至少理解了;它被传递到decrypt方法,然后“outputFile”应该返回到decrypt区域,然后在那里遍历其余的代码,这是我不理解的。但文件本身在其加密后保存到。。。桌面或用户选择的任何目录