Question: I have a file with too many lines.

Its constructed like:

```
Text
Text
Text

<--!Important Text begins here-->
important Text
Important Text
Important Text

<--!Important Text ends here -->

Unimportant Text
....

<--!Important Text begins here-->
important Text
Important Text
Important Text

<--!Important Text ends here -->

Unimportant Text
....<--!Important Text begins here-->
important Text
Important Text
Important Text

<--!Important Text ends here -->

Unimportant Text
....

```

and so on.

How can i take the important part and save it in a new file?
I am using the dash terminal from Macintosh

Answer: 
It's just a matter of finding a character set with an unmappable byte sequence.

Take, for example, [`IBM1098`](http://www.fileformat.info/info/charset/x-IBM1098/decode.htm). It can't map the hex bytes

```
0x80
0x81

```

So put these in a `ByteBuffer`, rewind it, and try to decode it.

```
public class Test {
    public static void main(String[] args) throws CharacterCodingException {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putInt(0x80);
        buffer.putInt(0x81);
        buffer.position(0);
        Charset charset = Charset.forName("IBM1098");
        CharsetDecoder decoder = charset.newDecoder();
        decoder.decode(buffer);
    }   
}

```

This throws

```
Exception in thread "main" java.nio.charset.UnmappableCharacterException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:282)
    at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:816)
    at com.test.Test.main(Test.java:16)

```

[Ideone.com attempt.](https://ideone.com/HEIUck)
When you supply a character to the decoder, the decoder can tell that a character is not appropriate for the charset and throw a UnmappableCharacterException.

When you supply a byte array to the encoder, is assumes that it has been encoded properly. Thus when it decodes your byte array and gets a bad character, it assumes you have a broken encoder or bad input, which causes a MalformedInputException.