java语言程序设计解答例题复习题答案.pdf
Chapter19BinaryI/O
1.Althoughitisnottechnicallyprecise,atextfileconsistsofasequenceof
charactersandabinaryfileconsistsofasequenceofbits.Youcanuseatext
editortoviewatextfile,butnotabinaryfile.
2.YouhavetouseJavaI/Oclassestocreateobjectsandusethemethodsinthe
objectstoperformI/O.AJavaI/Oobjectiscalledastream.Anobjectforreading
dataiscalledaninputstreamandanobjectforwritingdataiscalledanoutput
stream.
3.BinaryI/Oreadsabytefromafileandcopiesitdirectlytothememorywithany
conversion,viceversa.TextI/Orequiresencodinganddecoding.TheJVM
convertsaUnicodetoafilespecificencodingwhenwritingacharacterand
covertsafilespecificencodingtoaUnicodewhenreadingacharacter.
4.CharactersarerepresentedusingUnicodeinthememoryandcharactersare
representedinafileusingaspecifiedencodingscheme.Ifnoencodingschemeis
specified,thesystem’sdefaultencodingschemeisused.
5.Thevaluesstoredinthetextfileare0x410x420x43.
6.Ifyouwritestring100toanASCIItextfile,thevaluesstoredare0x310x30
0x30.Ifyouwriteanumericbyte-typevalue100usingbinaryI/O,thevalue
storedinthefileis0x64.
7.TheencodingschemeforrepresentingacharacterinaJavaprogramisthe
Unicode.Bydefault,atextfileisencodedusingASCII.
8.AlmostallthemethodsandconstructorsinJavaI/Oclasses,becausethereare