标签:
1, FileInputStream类函数创建:
package coreJava; import java.io.FileInputStream; import java.io.IOException; public class IOUtil { public static void printHex(String Filename)throws IOException{ /** * 读取指定文件内荣,按照16进制输出到控制台,并且 * 没输出10byte换行 */ FileInputStream in = new FileInputStream(Filename); int b; int i = 1; while((b = in.read())!=-1){ if(b <= 0xf){ //单位数前面补零 System.out.print("0"); } //以十六进制的形式输出显示,并且以空格分隔 System.out.print(Integer.toHexString(b)+" "); //当每行输出大于等于十个字节时换行 if(i++%10 == 0){ System.out.println(); } } //关闭文件,避免异常错误 in.close(); } }
2. 主函数:
package coreJava; import java.io.IOException; public class IOUtilTest1 { public static void main(String[] args)throws IOException { // TODO Auto-generated method stub IOUtil.printHex("E:\\JAVA IO\\testJava\\联通1.txt"); } }
标签:
原文地址:http://www.cnblogs.com/blogofwyl/p/4724896.html