解决方案 »
- java 自定义生成主键
- java绘图动画。。。闪屏。。老问题了。。帮一下把
- 初学者求教关于内部类
- 字段是text类型,是否能用setString ?(关于长文本插入数据库)
- 做JList时能编译但运行报空指向,请教各位大哥们
- 初学者问题,java2.0怎么用
- 怎么在IE里打开一个网址,java里有这个函数吗?
- 我要转学java了,时间不多了,大家给个方向吧! 先谢谢了!
- 请问大家,哪有中文的sl-275教材下载?
- 如何在Weblogic5.1中通过ODBC访问Access?
- 调试时怎么让Eclipse的悬停提示显示字段的值?
- Interger.tohexstring(int i)这个方法返回的是一个16进制数,我想让他返回的结果前面自动补0
不好意思阿,我太粗心啦
众大神帮忙阿~~
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
public class one {
public static void main(String[]args ) throws Exception{
outputFileWitHex("/home/wenwen/world.txt");
} private static void outputFileWitHex(String path) {
String result;
int n;
File file =new File(path);
try{
if(!file.exists()){
System.out.println(file.getName() + "不存在");
}else{
System.out.println(file.getName() + "存在");
}
FileInputStream in =new FileInputStream(file);
ByteArrayOutputStream out =new ByteArrayOutputStream();
byte[] b=new byte[1000];
while( (n = in.read(b))!= -1){
out.write(b, 0, n);
}
in.close();
out.close();
byte [] buffer = out.toByteArray();
for (int i=0 ;i<buffer.length ;i++){
String str = Integer.toHexString(buffer[i] & 0xFF);
result = str.toUpperCase() + "\t";
if(( i + 1) % 16 == 0)
result = result + "\n" ;
System.out.print(result);
}
}catch(Exception e){
e.printStackTrace();
}
}
}