title: Linux file size, java.nio and CP1252 multibyte character set
body: <p>I have an Cp1252 file that I want to read as binary.</p>
  
  <p><code>ls -al</code>  from the terminal shows its size is 10 bytes.</p>
  
  <p>This java snippet however reports 18 bytes:</p>
  
  <pre><code>Path path = Paths.get(lfile);
  SeekableByteChannel sbc = Files.newByteChannel(path, StandardOpenOption.READ);
  long size = sbc.size();
  </code></pre>
  
  <p>The file contains 6 ascii character + 4 Cp1252 characters. My understanding is that 10 bytes is the correct size of this file on the file system.
  One more detail: when trying to read the content of the file using:</p>
  
  <pre><code>byte[] fileContents = Files.readAllBytes(path);
  </code></pre>
  
  <p>I get 18 bytes, as each Cp1252 char is loaded as 3 bytes. In file I have different Cp1252 chars, buffer shows them all as being the same - which is incorrect for sure. </p>
  
  <p>Two questions bother me: </p>
  
  <ol>
  <li><p>How many bytes does this file actually take on a file system.</p></li>
  <li><p>Presuming that it is 10 bytes long, how to read it as "raw"</p></li>
  </ol>
  
  <p><strong>Update:</strong> 
  I tried the same using a small C program and results are as expected: 10 characters are read from the file and 4 of them that are Cp1252 are all of different value.</p>
  
  <pre><code>int main() {
      char fileName[200] = "test.x10";
      FILE *fp = fopen(fileName, "r");
      while(1) {
          int c = fgetc(fp);
          if( feof(fp) )
              break ;
          printf("%i ", c);
      }
      fclose(fp);
  }
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>test.x10 contains Cp1252 characters: <code>aöaäaüaßbb</code></p>
  
  <p>C code given above prints out: <code>97 246 97 228 97 252 97 223 98 98</code></p>
  
  <p>Files.readAllBytes reads: <code>97 239 191 189 97 239 191 189 97 239 191 189 97 239 191 189 98 98</code></p>
  
  <p>Here is the hexdump:</p>
  
  <pre><code>hexdump -C test.x10
  00000000  61 f6 61 e4 61 fc 61 df  62 62                   |a.a.a.a.bb|
  </code></pre>