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(" ");
     }
     }
    }

解决方案 »

  1.   

    public static void main(String[] args) {
    // 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);
    }
    }
      

  2.   

    楼主你好:
    有个问题想请教:
    我想write sector 但是发现 BufferOutputStream 没有skip的命令
    是否有相同的方法可以实现Write sector??