file io - Why do I get a java.nio.BufferUnderflowException in this Scala -
I was able to do something in some log file, try:
Scala & gt; Import io.Source Import io.Source Scala & gt; Import java.io.file import java.io.file scala & gt; Val f = New file (".") F: java.io.file =. Scala & gt; (L.L.L.; - f.listFiles) {| Val src = Source.fromFile (l) .getLines | Println ((0 /: src) {(i, line) => gt; i + 1}). } 3658 scala.io.BufferedSource java.nio.BufferUnderflowException on java.nio.Buffer.nextGetIndex (Unknown Source) at java.nio.HeapCharBuffer.get (Unknown Source) at $$ anon $ 2.next (BufferedSource.scala: 86 ) scala.io.Source $$ anon at $ 6.next: scala.io.Source to $$ anon $ 6.next (307 Source.scala): scala.io.BufferedSource $$ anon $ 2.next (74 BufferedSource .scala) (Source.scala: 301)? Scala.Iterator $ CLA ... Why do I get this java.nio.bufferUnderflowException
Note - I 10 log files in size, each processing is about 1 MB
me It should also know why this is happening, but I think it is the fact that source
is an object (i.e. a singleton) and how it is transparent Reset thus you can fix the problem Are:
(! L & lt; - g.listFiles if l.isDirectory) of {for | Val src = Source.fromFile (l) | Println ((0 /: src.getLines) {(i, line) = & gt; i + 1}) | Src.reset | }
is the important bit reset
- which should probably be in a try-end
block (though IsDirectory
test may be useful)
Comments
Post a Comment