用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); }}