package disk.sector;
import java.io.*;public class OpSector {public boolean readSector(String diskSign, byte[]buf, int startSector, int length)
{
try{
FileInputStream fr = new FileInputStream(diskSign);
BufferedInputStream br = new BufferedInputStream(fr);
br.skip(startSector*512);
br.read(buf, 0, length);
br.close();
fr.close();
}catch(IOException e)
{
System.out.println(e.getMessage());
return false;
}
return true;
}public void sectorDataFormat(byte[] buf)
{
for(int i = 0;i< buf.length;i++)
{
Byte byteObject = new Byte(buf[i]);
// String restr = Integer.toHexString(byteObject.intValue());
int restr = byteObject.intValue();
if(restr < 0)
{
restr = 0x100 + restr;
}
if(restr < 0x10)
{
System.out.print(0);
}
System.out.print(Integer.toHexString(restr) +" ");
if(i%512 == 511)
{
System.out.println(" "+(i/512+1));
}else
if(i%16 ==15)
{
System.out.println(" ");
}else if(i%8 == 7)
{
System.out.print(" ");
}
}
}
import java.io.*;public class OpSector {public boolean readSector(String diskSign, byte[]buf, int startSector, int length)
{
try{
FileInputStream fr = new FileInputStream(diskSign);
BufferedInputStream br = new BufferedInputStream(fr);
br.skip(startSector*512);
br.read(buf, 0, length);
br.close();
fr.close();
}catch(IOException e)
{
System.out.println(e.getMessage());
return false;
}
return true;
}public void sectorDataFormat(byte[] buf)
{
for(int i = 0;i< buf.length;i++)
{
Byte byteObject = new Byte(buf[i]);
// String restr = Integer.toHexString(byteObject.intValue());
int restr = byteObject.intValue();
if(restr < 0)
{
restr = 0x100 + restr;
}
if(restr < 0x10)
{
System.out.print(0);
}
System.out.print(Integer.toHexString(restr) +" ");
if(i%512 == 511)
{
System.out.println(" "+(i/512+1));
}else
if(i%16 ==15)
{
System.out.println(" ");
}else if(i%8 == 7)
{
System.out.print(" ");
}
}
}
解决方案 »
- action里定义一个long[]数组,如何把该数组传递到JSP,然后又传回action
- 【初学】Hibernate配置基础问题。
- 关于焦点
- 当一个运行线程抛出异常后,该线程会变成什么状态?
- 新手求教 System.out.println与System.out.print区别
- 如何下载网站
- 如何知道ResultSet中有多少条记录?
- 给大四的学生上课,用什么教材比较好呢?
- 香港公司购买一个在线 GAME 的软件,出价 3.5万-4万 ,用JAVA编写或类似技术,有大虾自己有现成可以出售吗?
- 有没有收到了JREPORT的userid和licence key!求救!!!
- java中 菜单中的事件处理
- 如何在rcp 中实现多个工作台窗口 并且各个工作台窗口菜单栏和工具栏不同
// TODO Auto-generated method stub
OpSector op = new OpSector();
int startSector = 0;
int length = 0x200;
byte[] buf = new byte[length];
if(op.readSector(diskSign, buf, startSector, length))
{
System.out.println("read sector success");
}else{
System.out.println("read sector error");
}
op.sectorDataFormat(buf);
}
}
有个问题想请教:
我想write sector 但是发现 BufferOutputStream 没有skip的命令
是否有相同的方法可以实现Write sector??