1

I'm on ubuntu 13.10 and am writing a program in eclipse that's supposed to output my result in a file. I'm building an LZW compression and decompression program that uses character conversion to its code. On console everything outputs fine. But when I try to redirect the output to a file (something.txt), all am getting is something like this:

扡聡膀蚃膂詢誋

{EDIT}

cat somthing.txt shows the following:

aba�������b���

locale says:

LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_CTYPE="en_US.UTF-8" LC_NUMERIC=en_GB.UTF-8 LC_TIME=en_GB.UTF-8 LC_COLLATE="en_US.UTF-8" LC_MONETARY=en_GB.UTF-8 LC_MESSAGES="en_US.UTF-8" LC_PAPER=en_GB.UTF-8 LC_NAME=en_GB.UTF-8 LC_ADDRESS=en_GB.UTF-8 LC_TELEPHONE=en_GB.UTF-8 LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=en_GB.UTF-8 LC_ALL=

where ababbababaaab is the input of my program and the output should be the ascii numbers of some of these characters

I tried to change the encoding from terminal but nothing changed. Any idea what's the problem?

  • What does locale say? What does your-program | hexdump -C say? How do you view the file? E.g. what does cat something.txt show you on the console? – 9000 Nov 5 '14 at 14:25
  • @9000 I editted it. – user2949483 Nov 5 '14 at 14:35
  • 1
    My suspicion is that you are not writing the repeat counts as numbers (printf("%d", count)), but write them as naked bytes. Try the | hexdump -C thing and check what characters come after aba. – 9000 Nov 5 '14 at 14:43
  • How should we know? Your program's output isn't what you expect, but you haven't shown us your program's code. – Gilles 'SO- stop being evil' Nov 6 '14 at 23:15
  • @Gilles I was writing on a file in a way that outputed right while trying it on Windows. It's ubuntu default files encoding or sometihng that caused the weird characters. – user2949483 Nov 7 '14 at 15:35
1

Problem disappeared using PrintWriter and setting its parameter to UTF-8 instead of DataOutputStream while writing on my file. (Java)

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.