Reading from file (by bit) and then writing again to file
<p>i can't figure out about working with I/O.</p>

<p>I am using this code to read from file:</p>

<pre><code>if (file.length() &gt; Integer.MAX_VALUE) {
    throw new IllegalArgumentException("File is too large: " + file.length());
}

int len = (int) file.length();
System.out.println("failo dydis yra = "+len);
FileInputStream inputStream = new FileInputStream(file);

try {
    byte[] fileBits = new byte[len];
    for (int pos = 0; pos &lt; len;) {
        int n = inputStream.read(fileBits, pos, len - pos);

        if (n &lt; 0) {
            throw new EOFException();
        }
        pos += n;

    }
    for(int q=0; q&lt;len; q++){
        char ch = (char)fileBits[q];
        int sk = (int)ch;
        System.out.println("symbol = "+fileBits[q]+" - "+ch+" - "+sk);
    }
</code></pre>

<p>When i read txt file then everything is nice but when i read not txt for example image i get similar result:</p>

<pre><code>symbol = -78 - ﾲ - 65458
symbol = 52 - 4 - 52
symbol = -91 - ﾥ - 65445
symbol = 80 - P - 80
symbol = -118 - ﾊ - 65418
symbol = 76 - L - 76
symbol = 122 - z - 122
symbol = 78 - N - 78
symbol = 112 - p - 112
symbol = 97 - a - 97
symbol = 56 - 8 - 56
symbol = -112 - ﾐ - 65424
</code></pre>

<p>So i can't figure why there are <strong>minus</strong> ? And why when i want to convert back i get this 65***.</p>

<p>Maybe i have to read different if i want to convert these bytes to chars, work with them and write again to file.</p>

<p>Thanks. </p>
