Buffered Reader read text until character

Waggoner_Keith

I am using a buffered reader to read in a file filled with lines of information. Some of the longer lines of text extend to be more than one line so the buffered views them as a new line. Each line ends with ';' symbol. So I was wondering if there was a way to make the buffered reader read a line until it reaches the ';' then return the whole line as a string. Here a how I am using the buffered reader so far.

  String currentLine;
        while((currentLine = reader.readLine()) != null) {
            // trim newline when comparing with lineToRemove
            String[] line = currentLine.split(" ");
            String fir = line[1];
            String las = line[2];
            for(int c = 0; c < players.size(); c++){
                if(players.get(c).getFirst().equals(fir) && players.get(c).getLast().equals(las) ){
                    System.out.println(fir + " " + las);
                    String text2 = currentLine.replaceAll("[.*?]", ".150");
                    writer.write(text2 + System.getProperty("line.separator"));
                }
            }
        }
Mureinik

It would be much easier to do with a Scanner, where you can just set the delimiter:

Scanner scan = new Scanner(new File("/path/to/file.txt"));
scan.useDelimiter(Pattern.compile(";"));
while (scan.hasNext()) {
    String logicalLine = scan.next();
    // rest of your logic
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Get all text from a Div after a '-' up until the first character

分類Dev

grep --line-buffered until X lines?

分類Dev

How to handle exceptions when reading files with buffered reader?

分類Dev

Read data to Text File and reserve de output with N character

分類Dev

Regular expression to match until '{' character?

分類Dev

Read until end of channel in Go

分類Dev

Why does RandomAccessFile read  as firt character in my UTF-8 text file?

分類Dev

Read input into string in Lisp reader macro

分類Dev

Delete characters until a certain character from string

分類Dev

Keep appending to list until a character amount is reached

分類Dev

Cannot copy text from Acrobat reader on Ubuntu

分類Dev

Character Position in a Text

分類Dev

Edit Text first character as $

分類Dev

Pandas read csv ignoring " character

分類Dev

Boost :: Asio-readまたはread_until?

分類Dev

Understanding why a Java pattern matches incorrect text inside buffered .java file?

分類Dev

How to use Driver Wait Until Text is in selenium

分類Dev

Remove the text until the matching string using regex

分類Dev

GREP lines from file in another file until occurence of a certain character

分類Dev

How to create a text file and write text character by character using MATLAB?

分類Dev

Sublime Text go to character number

分類Dev

Sublime Text go to character number

分類Dev

Sublime Text go to character number

分類Dev

Force EPPLUS to read as text

分類Dev

How to extract first character and numbers after that until find a character (a-z) in a string - C# 2.0

分類Dev

Escape New line character in Spark CSV read

分類Dev

Read from a certain point to a certain character

分類Dev

golang - bufio read multiline until (CRLF) \r\n delimiter

分類Dev

How to read until EOF and print the even/odd numbers entered?

Related 関連記事

  1. 1

    Get all text from a Div after a '-' up until the first character

  2. 2

    grep --line-buffered until X lines?

  3. 3

    How to handle exceptions when reading files with buffered reader?

  4. 4

    Read data to Text File and reserve de output with N character

  5. 5

    Regular expression to match until '{' character?

  6. 6

    Read until end of channel in Go

  7. 7

    Why does RandomAccessFile read  as firt character in my UTF-8 text file?

  8. 8

    Read input into string in Lisp reader macro

  9. 9

    Delete characters until a certain character from string

  10. 10

    Keep appending to list until a character amount is reached

  11. 11

    Cannot copy text from Acrobat reader on Ubuntu

  12. 12

    Character Position in a Text

  13. 13

    Edit Text first character as $

  14. 14

    Pandas read csv ignoring " character

  15. 15

    Boost :: Asio-readまたはread_until?

  16. 16

    Understanding why a Java pattern matches incorrect text inside buffered .java file?

  17. 17

    How to use Driver Wait Until Text is in selenium

  18. 18

    Remove the text until the matching string using regex

  19. 19

    GREP lines from file in another file until occurence of a certain character

  20. 20

    How to create a text file and write text character by character using MATLAB?

  21. 21

    Sublime Text go to character number

  22. 22

    Sublime Text go to character number

  23. 23

    Sublime Text go to character number

  24. 24

    Force EPPLUS to read as text

  25. 25

    How to extract first character and numbers after that until find a character (a-z) in a string - C# 2.0

  26. 26

    Escape New line character in Spark CSV read

  27. 27

    Read from a certain point to a certain character

  28. 28

    golang - bufio read multiline until (CRLF) \r\n delimiter

  29. 29

    How to read until EOF and print the even/odd numbers entered?

ホットタグ

アーカイブ