Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. String content = new Scanner(new File("filename")).useDelimiter("\Z").next();
  2. System.out.println(content);
  3.  
  4. FileInputStream fisTargetFile = new FileInputStream(new File("test.txt"));
  5.  
  6. String targetFileStr = IOUtils.toString(fisTargetFile, "UTF-8");
  7.  
  8. String content = new Scanner(new File("filename")).useDelimiter("\Z").next();
  9. System.out.println(content);
  10.  
  11. final String CHARSET = "UTF-8";
  12. final String DELIMITER = "Some text that is unlikely to occur in the file";
  13. File file = new File("filename")
  14. Scanner scanner = new Scanner(file,CHARSET).useDelimiter(DELIMITER);
  15. String content = null;
  16. if (scanner.hasNext())
  17. content = scanner.next();
  18. if (scanner.hasNext())
  19. throw new IllegalStateException("DELIMITER occurs in file. Use a different delimiter");
  20. if (file.length() != content.getBytes(CHARSET).length)
  21. throw new IllegalStateException("Inconsistent file lengths. Probably a charset related problem.");
  22. System.out.println(content);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement