Reading file using java and jcifs on windows. I need to determine size of file, which contains multi-byte as well as ASCII characters.
how can i achieve it efficiently OR any existing API in java?
Thanks,
No doubts, to get exact number of characters you have to read it with proper encoding. The question is how to read files efficiently. Java NIO is fastest known way to do that.
FileChannel fChannel = new FileInputStream(f).getChannel();
byte[] barray = new byte[(int) f.length()];
ByteBuffer bb = ByteBuffer.wrap(barray);
fChannel.read(bb);
then
String str = new String(barray, charsetName);
str.length();
Reading into byte buffer is done with a speed near to maximum available ( for me it was like 60 Mb/sec while disk speed test gives about 70-75 Mb/sec)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With