当前位置: 代码迷 >> J2SE >> 用java如何从指定文件中的指定位置开始读取指定长度的内容?多谢
  详细解决方案

用java如何从指定文件中的指定位置开始读取指定长度的内容?多谢

热度:83   发布时间:2016-04-24 12:16:43.0
用java怎么从指定文件中的指定位置开始读取指定长度的内容?谢谢
用java怎么从指定文件中的指定位置开始读取指定长度的内容?谢谢

------解决方案--------------------
Java code
public class Test {     public static void main(String[] args) {         System.out.println(read(3,9));    }     public static String read(int from ,int to){        String result="";        byte[] result2=new byte[to-from+1];        try{            FileInputStream fis=new FileInputStream("d:\\ss.txt");            BufferedInputStream bis=new BufferedInputStream(fis);             bis.skip(from-1);            bis.read(result2, 0, to-from+1);        }catch(FileNotFoundException e){            e.printStackTrace();        }catch(IOException e){            e.printStackTrace();        }        return new String(result2);    }}
  相关解决方案