首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

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

2012-02-10 
用java怎么从指定文件中的指定位置开始读取指定长度的内容?谢谢用java怎么从指定文件中的指定位置开始读取

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

热点排行