Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
968 B

  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. /**
  6. * Simple class for reading files as strings.
  7. *
  8. * @author Jeffery Russell
  9. */
  10. public class FileReader
  11. {
  12. public static String readFile(String filePath)
  13. {
  14. String fileContent = new String();
  15. try
  16. {
  17. BufferedReader br = new BufferedReader(
  18. new InputStreamReader(new FileInputStream(filePath)));
  19. String line;
  20. while ((line = br.readLine()) != null)
  21. {
  22. fileContent = fileContent.concat(line);
  23. }
  24. br.close();
  25. }
  26. catch (IOException e)
  27. {
  28. e.printStackTrace();
  29. }
  30. return fileContent;
  31. }
  32. public static void main(String[] args)
  33. {
  34. System.out.println("Test");
  35. System.out.println(FileReader.readFile("./testData/data1.txt"));
  36. }
  37. }