Starting from:
$30

$24

Practice2 Solution

Question 1

Please write a program named “CharsetConvertor” that converts a file to a specified encoding.

If run the command:


 java CharsetConvertor sample.txt gb18030 utf8


Then generate the target file in the same directory as the original file. If the original filename is sample.txt, the target filename is sample_utf8.txt.







Question 2

Given some files with an unknown extension or mislabeled name. Assuming that these files are normal, non-empty files, how do you determine what type of files they are?

You can try to use the file header to help determine what type the file is.

Three files are given now. Please analyze their types according to the following table


File header(Hex)
File Type
89504e47
png
504b0304
zip or jar
cafebabe
class




If run the command:


 java FileTypeParser HelloWorld



Output:


Filename:HelloWorld

File Header(Hex):[ca, fe, ba, be]


 File Type: class


Evaluation Criteria:

The practice will be checked on this to the next next lab class(Mar.9) by teachers or

SAs. What will be tested:

    1. That you understand every line of your own code, not just copy from somewhere

    2. That your program compiles correctly (javac)

    3. Correctness of the program logic

    4. That the result is obtained in a reasonable time

This practice will contribute 1 mark to your overall grade. Late submissions within 2 weeks after the deadline (Mar.9)will incur a 20% penalty, meaning that you can only get 80% of the score.

More products