Line Number Reader

2019-08-15 10:53发布

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.

2条回答
一夜七次
2楼-- · 2019-08-15 11:35

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();
查看更多
狗以群分
3楼-- · 2019-08-15 11:48

Yeah, use:

int skippedLines = 1523;
LineNumberReader reader = new LineNumberReader(new FileReader(new File("file.txt")));
reader.skip(skippedLines);
查看更多
登录 后发表回答