I'm not sure I quite understand what you want, do you have a code example?
As a side note I doubt you'd need to worry about compressing 10 lines of string data.
How about create a byte array the same size as the paragraph and simply put the lower order bytes of the chars into the byte array, and then save it as a non-text file.
--- Update ---
Heck, String has a getBytes() method. Have you tried working with this?
Where is the code that outputs the unicode? Where is the unicode text written? How did you copy and paste here the unicode values shown in your post?
When I compile and execute the program I get the text not unicode.
What does this mean:Quote:
When you convert the string to unicode
So your program takes a file input which you have to be able to parse, write to an output file (presumably smaller than the original input file), then be able to re-construct the original content and display it?
A few questions:
1. Is unicode output support a requirement? If it isn't, you can quickly chop your data size in half by switching to an 8-bit encoding like ASCII.
2. Does your input file look exactly like what you posted? That file only has ~100 actual characters. You can use various functions in the Character class to parse the string "\u0063" into the actual unicode character.
3. I doubt you're being asked to implement a fully-fledged compression algorithm. If your professor is looking for use of an actual compression algorithm, take a look at the java.util.zip package. It has implementations of the zip and gzip algorithms which you can call to compress/decompress files.
I am confused about what the program is doing.Quote:
unicode was supplied by the teacher
Finally, the unicode is:
Is that the contents of a text file that you are supposed to read and convert to a Java String?
\u0063 to c
\u006C to l
You could put all of the text into a single String. Use the line separator character in the String at the places where you want a new line to begin.Quote:
This is what I have to print out
So the total text of the program outside of the paragraph has to be 138 bytes?Quote:
I have to make the paragraph no more than 655 bytes, with a total of 793 bytes for the whole entire program.
Seems a big waste of time. What is supposed to be learned in this exercise?
How are you learning compression by retyping the lines of a program?
Norm is commenting on the assignment itself, not your questions. I agree that this looks like a pointless exercise.
Are you counting bytes of source code, or bytes of the compiled program?
I just compiled a pretty much as bare-bones program I that will work by reading an uncompressed text file in and the printing it out and that's an 1008 byte binary.
Putting all the code on one line will save the lineend characters for each line.Quote:
changed the "args" to "a", saving 3 bytes
That's rather silly to count the bytes of the source file (that's the .java file, the .class file is the compiled binary). It encourages bad programming practices like single letter variable names, no tabbing, no comments, and no line separators. Even taking all of these things out the source file is 860 characters long.
I wouldn't bother, Java source files are usually UTF-8 encoded, meaning if you only use characters in the lower 128 ASCII charset you'll get the exact same file either way (that's the case here).Quote:
I cannot pass in any inputs for this. Here's what I was thinking. Convert this string to ascii, and compress that ascii code (because there may be repeating characters). Then place this compressed ascii code in a java program, and somehow find a class to uncompress it??? That way, this should not take up too much space.
The only way I can think of to get your source file smaller is to use an external file, then your java program opens that file and prints it out.
When is your assignment due? I would recommend asking a member of the teaching staff if you're able to. These seem like rather silly requirements, and they might shed some light on what path you're expected to take.
Having an externally compressed text file won't help much because then you'll need to have Java code which will decompress it. If you do end up compressing it, leave the text "as-is" so you don't have to do an extra step converting hex to a character code. The best solution I can think of is reading from an uncompressed text file and printing it out.
There's no way to directly store an image in a java source file, besides you're storing the same data either way. The character 'A' has a value of 65, which is 1 byte regardless of if it's interpreted as a pixel or as an UTF-8 character.