java - Behavior of using \Z vs \z as Scanner delimiter -
[edit] found answer, can't answer question due restrictions on new users. either way, known bug in java.
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8028387
i'm trying read file string in java 6 on 64 bit ubuntu. java giving me strange result "\\z" reads entire file, "\\z" reads entire string 1024 characters. i've read java 6 api classes , @ loss.
description of \z , \z can found at:
http://docs.oracle.com/javase/6/docs/api/java/util/regex/pattern.html#lt
what causing strange behavior?
string filestring = new scanner(new file(filename)).usedelimiter("\\z").next(); string filestring2 = new scanner(new file(filename)).usedelimiter("\\z").next(); system.out.println("using z : " + filestring2.length()); system.out.println("using z "+ filestring.length()); output: using z : 9720 using z : 1024
thanks!
details file/java-version:
running ubuntu java-6-openjdk-amd64 (tested oracle java6) file simple text file utf-8 encoded.
as pattern documentation states
\zend of input\zend of input final terminator, if any
i suspect since scanners buffer size set 1024,
354 private static final int buffer_size = 1024; // change 1024;
scanner reads amount of characters , uses current input, \z can used here represent end, while \z can't because not "final terminator" (there more elements in entire input read).
Comments
Post a Comment