為什么第一行提前換行
import?java.io.File; import?java.io.FileInputStream; import?java.io.IOException; public?class?Demo?{ ????public?static?void?main(String[]?args)?throws?IOException{ ????????Demo?demo?=?new?Demo(); demo.go("E:\\testdata\\directory1\\text1.txt"); ????} ????public?void?go?(String?fn)?throws?IOException{ ????????if(!?(new?File(fn)).exists())?{ ????????????IOException?ioe?=?new?IOException("文件不存在"); ????throw?(ioe); ????????}else?{ ????FileInputStream?fis?=?new?FileInputStream(fn); ????fis.read(); ???? ????int?aa; ????int?bb?=?1; ????while((aa?=?fis.read())?!=?-1)?{ if((bb++?%?10)?==?0)?{ ????System.out.println(); } if(aa?<=?0xF)?{ ????System.out.print(0); ????????} ????????System.out.print(Integer.toHexString(aa)?+?","); ????} ????fis.close(); ????????} ????} }
代碼是這樣寫的,文件text1.txt中的內(nèi)容是:There is a very beautiful city called Loulan,which locates in the west of ancient China.,輸出結(jié)果卻是:
68,65,72,65,20,69,73,20,61,
20,76,65,72,79,20,62,65,61,75,
74,69,66,75,6c,20,63,69,74,79,
20,63,61,6c,6c,65,64,20,4c,6f,
75,6c,61,6e,2c,77,68,69,63,68,
20,6c,6f,63,61,74,65,73,20,69,
6e,20,74,68,65,20,77,65,73,74,
20,6f,66,20,61,6e,63,69,65,6e,
74,20,43,68,69,6e,61,2e,
為何第一行提前了一下?
2019-05-29
你自己心算下i和輸出,對應(yīng)一下。把i初始值賦為0就行了。
2019-02-20
這應(yīng)該是文件拷貝時,文件寬度到了自動換的行,還有可能是編譯器自動換的行