Line Number Reader

穿精又带淫゛_ 提交于 2020-01-06 04:01:46

问题


I got some problems with my Code

window.videoInfo.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

     try {

     URL url = new URL(window.videoInput.getText());
     URLConnection con = url.openConnection();

   LineNumberReader in = new LineNumberReader(new InputStreamReader(con.getInputStream()));
   in.setLineNumber(1523);
   in.getLineNumber();

      System.out.print(in.readLine());

     } catch (IOException ex) {
        ex.printStackTrace(); 

     }

I am trying to display a specific Line from a website. But if i press the button it always displays the first line. Even when i set the line Number to 1523.


回答1:


setLineNumber(1523) only makes the line number returned by getLineNumber() starts with 1523. It won't skip 1523 lines. To skip 1523 lines, you need to do:

for(int i = 0; i < 1523; i++)
    in.readLine();



回答2:


Yeah, use:

int skippedLines = 1523;
LineNumberReader reader = new LineNumberReader(new FileReader(new File("file.txt")));
reader.skip(skippedLines);


来源:https://stackoverflow.com/questions/16623990/line-number-reader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!