For my encryption software, I have to decrypt the contents of a JTextArea when the decryption button is pressed.

How do I get a byte[] containing the contents of my text area?

有帮助吗?

解决方案

From your limited description, it sounds like you want to retrieve text from a JTextArea in the form of bytes.

This is straight-forward enough:

byte[] data = yourTextArea.getText().getBytes("charset-name");

Replace "charset-name" with your preferred character set.

其他提示

If your encrypted data starts with "[B@" it means that you are using ".toString()" in your code and it isnt the real encrypted data. To prove it, print the length too and you will see that its a lot longer. If you want the encrypted data do a for loop like this:

byte[] encryptedText=encrypt("Hello");

for(int i=0;i<encryptedText.length();i++) {
String s=String.valueOf(encryptedText[i]);
System.out.print(s);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top