Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. public String findFile()
  2. {
  3. String line = "";
  4.  
  5. try
  6. {
  7. File myDir = new File("files");
  8. File myFile = new File(myDir, "ISBN 123-654.txt");
  9. BufferedReader br = new BufferedReader(new FileReader(myFile));
  10.  
  11. while ((line = br.readLine()) != null)
  12. {
  13. System.out.println(line + "1");
  14. }
  15. }
  16. catch (IOException e)
  17. {
  18. e.printStackTrace();
  19. }
  20.  
  21. System.out.println(line+"2");
  22. return line;
  23. }
  24.  
  25. public String findFile()
  26. {
  27. String line = "";
  28. try {
  29. File myFile = new File("files", "ISBN 123-654.txt");
  30. BufferedReader br = new BufferedReader(new FileReader(myFile));
  31.  
  32. while ((line = br.readLine()) == null)
  33. System.out.println(line + "1");
  34. br.close();
  35. }
  36. catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39.  
  40. System.out.println(line+"2");
  41. return line;
  42. }
  43.  
  44. public String findFile(){
  45. String fileContent = "";
  46.  
  47. try {
  48. File myDir = new File("files");
  49. File myFile = new File(myDir, "ISBN 123-654.txt");
  50. BufferedReader br = new BufferedReader(new FileReader(myFile));
  51.  
  52. String line;
  53. while ((line = br.readLine()) != null){
  54. System.out.println(line + "1");
  55. fileContent += line;
  56. }
  57. }
  58. catch (IOException e){
  59. e.printStackTrace();
  60. }
  61. System.out.println(fileContent+"2");
  62. return fileContent;
  63. }
  64.  
  65. public String findFile()
  66. {
  67. String line = "";
  68. String rtLine = null;
  69.  
  70. try
  71. {
  72. File myDir = new File("files");
  73. File myFile = new File(myDir, "ISBN 123-654.txt");
  74. BufferedReader br = new BufferedReader(new FileReader(myFile));
  75.  
  76. while ((line = br.readLine()) != null)
  77. {
  78. rtLine = line;
  79. System.out.println(line + "1");
  80. }
  81. }
  82. catch (IOException e)
  83. {
  84. e.printStackTrace();
  85. }
  86.  
  87. System.out.println(line+"2");
  88. return rtLine;
  89. }
  90.  
  91. try {
  92. List<String> lines = Files.readLines(new File(PATH_TO_FILE), Charsets.UTF_8);
  93. //return content lines separated by comma
  94. return Joiner.on(",").join(lines);
  95.  
  96. } catch (IOException e) {
  97. e.printStackTrace();
  98. }
  99.  
  100. try {
  101. List<String> lines = Files.readLines(new File(PATH_TO_FILE), Charsets.UTF_8);
  102. //return last line
  103. if (lines.size() > 0) {
  104. return lines.get(lines.size() - 1);
  105. } else {
  106. return null;
  107. }
  108.  
  109. } catch (IOException e) {
  110. e.printStackTrace();
  111. }
  112.  
  113. File myFile = new File("files", "ISBN 123-654.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement