Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Character.reverseBytes error!



Hello,
I have written some code to encrypt the contents of a textfile by using the method Character.reverseBytes as shown below:

    try {
        reader = new BufferedReader(new FileReader(file));
        writer = new BufferedWriter(new FileWriter(outfile));
        String text = "";
        // repeat until all lines are read
        while ((text = reader.readLine()) != null) {
            String reverseText = "";
            for (int i=0; i<text.length(); i++) {
                reverseText += Character.reverseBytes(text.charAt(i));
            }
            writer.append(reverseText + "\n");
        }

Then I use the same method to decrypt the contents of the encrypted textfile.

The thing is that when I execute this code from NetBeans, it can encrypt and decrypt the file fine.
However if I execute the java code from my computer as standalone program, encrypting returns a textfile full of "?" sings. And then when I try to decrypt it, I still get the same "?" signs.
Why is that?
Can you help?
Thank you very much for your valuable time.