agrison / jtoml

TOML for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parse a File can fail deppending on text content

asfixia opened this issue · comments

The parser will fail for a file with the following content.
title = "anything é "

The problem is caused by the function Util.FileToString.read(File file) that does not support accented characters.

I fixed using the Apache CommonIO FileUtils.readFileToString but this function can solve the problem:

public static class FileToString {
        public static String read(File file)
          throws FileNotFoundException {
            String result = "";
            DataInputStream in = null;
            try {

            byte[] buffer = new byte[(int) file.length()];
            in = new DataInputStream(new FileInputStream(file));
            in.readFully(buffer);
            result = new String(buffer);
            } catch (IOException ex) {
                throw new FileNotFoundException(ex.getMessage());
            }
            return result;
        }
}

cheers