Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public static void main(String[] args) {
  2. String tempString = "";
  3. String tempStringTwo = "";
  4. String [] convertedLines = new String [100];
  5. int counter = 0;
  6. int tempcount = 0;
  7.  
  8. File file = new File("input.txt");
  9. if (!file.exists()) {
  10. System.out.println(args[0] + " does not exist.");
  11. return;
  12. }
  13. if (!(file.isFile() && file.canRead())) {
  14. System.out.println(file.getName() + " cannot be read from.");
  15. return;
  16. }
  17. try {
  18. FileInputStream fis = new FileInputStream(file);
  19. char current;
  20.  
  21. while (fis.available() > 0) { // Filesystem still available to read bytes from file
  22. current = (char) fis.read();
  23. tempString = tempString + current;
  24. int character = (int) current;
  25. if (character==13) { // found a line break in the file, need to ignore it.
  26. //tempString = tempString.replace("n"," ").replace("r"," ");
  27. tempString = tempString.replaceAll("\r|\n", " ");
  28. //tempString = tempString.substring(0,tempString.length()-1);
  29. //System.out.println(tempString);
  30. }
  31. if (character==46) { // found a period
  32. //System.out.println("Found a period.");
  33. convertedLines[counter] = tempString;
  34. tempString = "";
  35. counter++;
  36. tempcount = counter;
  37. }
  38.  
  39. }
  40. } catch (IOException e) {
  41. e.printStackTrace();
  42. }
  43. System.out.println("------------------------------------------------");
  44. for (int z=0;z<tempcount;z++){
  45. System.out.println(convertedLines[z]);
  46. }
  47. }
  48.  
  49.  
  50. Here's my current output...
  51. ------------------------------------------------
  52. The quick brown fox
  53. jumps over the lazy dogs.
  54. Now is the time for all good men to come to the
  55. aid of their country.
  56. All your base are
  57. belong to us.
  58.  
  59. Here's what I need...
  60. -----------------------------------------------------
  61. The quick brown fox jumps over the lazy dogs.
  62. Now is the time for all good men to come to the aid of their country.
  63. All your base are belong to us.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement