- Java code
InputStream in = new FileInputStream(file);BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));long count = 0; String line = br.readLine(); while (line != null) { count += line.getBytes("UTF-8").length; count += 1; // Add \r's length System.out.println(Thread.currentThread() + " " + line); System.out.println(" count:" + count); line = br.readLine(); }
求问为什么count计算的字节数和实际的字节数不一样
------解决方案--------------------
- Java code
InputStream in = new FileInputStream(file);System.out.println(in.available());