Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String content = new Scanner(new File("filename")).useDelimiter("\Z").next();
- System.out.println(content);
- FileInputStream fisTargetFile = new FileInputStream(new File("test.txt"));
- String targetFileStr = IOUtils.toString(fisTargetFile, "UTF-8");
- String content = new Scanner(new File("filename")).useDelimiter("\Z").next();
- System.out.println(content);
- final String CHARSET = "UTF-8";
- final String DELIMITER = "Some text that is unlikely to occur in the file";
- File file = new File("filename")
- Scanner scanner = new Scanner(file,CHARSET).useDelimiter(DELIMITER);
- String content = null;
- if (scanner.hasNext())
- content = scanner.next();
- if (scanner.hasNext())
- throw new IllegalStateException("DELIMITER occurs in file. Use a different delimiter");
- if (file.length() != content.getBytes(CHARSET).length)
- throw new IllegalStateException("Inconsistent file lengths. Probably a charset related problem.");
- System.out.println(content);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement