Kostiantyn Palianychka
Kostiantyn Palianychka

Reputation: 595

Parsing separated text file in Scala

When i trying parse txt file at 200k line in file i have this error:

java.nio.charset.UnmappableCharacterException: Input length = 1

After i got error my program break:

val bufferedSource = io.Source.fromFile( path)
for (line <- bufferedSource.getLines.drop(1)) {
    line.split('|').toList.drop(1)
    }

If I understand correctly, the error is in io.Source.fromFile( path). How i can skip bad rows ?

Upvotes: 1

Views: 249

Answers (1)

Sami Badawi
Sami Badawi

Reputation: 1032

Unfortunately you have to deal with encodings issues yourself. One of these 2 encodings often work for me:

val bufferedSource = io.Source.fromFile( path, enc = Codec.UTF8.name)
for (line <- bufferedSource.getLines.drop(1)) {
    line.split('|').toList.drop(1)
    }

or

val bufferedSource = io.Source.fromFile( path, enc = Codec.ISO8859.name)

Upvotes: 1

Related Questions