fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.text.*;
  5. import static java.lang.System.*;
  6.  
  7. //public
  8. class FileCopier
  9. {
  10. static Scanner in = new Scanner(System.in);
  11. static String file, line, newFile;
  12. static int location;// = file.indexOf(".");
  13. static File filename, fileTwo;
  14. static boolean compare = false;
  15. public static void main (String[] args) throws IOException
  16. {
  17. GetFile();
  18. System.out.println("Checking file");
  19. if(CompareExtension() != false)
  20. {
  21. System.out.println("Finding file...");
  22. if(filename.isFile() != false) //Checks if file is real and can be read
  23. {
  24. compare = true;
  25. System.out.println("Checking if readable...");
  26. if(filename.canRead() != false)
  27. {
  28. compare = true;
  29. System.out.println("Result: " + compare);
  30. if(compare == true)
  31. {
  32. System.out.println("Creating new file...");
  33. nameNewFile();
  34. System.out.println("Coping file...");
  35. CopyFile();
  36. System.out.print("Complete");
  37. // System.exit();
  38. }
  39. else
  40. {
  41. System.out.print("Coping: " + compare);
  42. }
  43. }
  44. else
  45. {
  46. System.out.print("Readable: " + compare);
  47. }
  48. }
  49. else
  50. {
  51. compare = false;
  52. System.out.print("File existance: " + compare);
  53. // System.exit();
  54. }
  55. }
  56. else
  57. {
  58. System.out.println("Error: File not found.");
  59. }
  60. }
  61. public static void GetFile() throws IOException
  62. {
  63. System.out.print("What file do you want to copy?(Include extension) ");
  64. file = in.nextLine();
  65. filename = new File(file);
  66. }
  67. public static boolean CompareExtension()
  68. {
  69. String[] extensions = {".bat", ".602", ".abw", ".acl", ".afp", ".ami", ".ans", ".asc", ".aww", ".ccf", ".csv", ".cwk", ".dat", ".dbk", ".doc", ".docm", ".docx", ".dot", ".dotx", ".egt", ".epub", ".ezw", ".fdx", ".ftm", ".ftx", ".gdoc", ".html", ".htm", ".hwp", ".hwpml", ".log", ".lwp", ".mbp", ".md", ".mcw", ".mobi", ".nb", ".nbp", ".odm", ".odt", "out", ".ott", ".omm", ".pages", ".pap", ".pdax", ".pdf", ".rtf", ".quox", ".rpt", ".sdw", ".se", ".stw", ".sxw", ".tex", ".info", ".troff", ".txt", ".uof", ".uoml", ".via", ".wpd", ".wps", ".wpt", ".wrd", ".wrf", ".wri", ".xhtml", ".xml", ".xps", ".java"};
  70. location = file.indexOf(".");
  71. for(int n = 0; n < extensions.length; n++)
  72. {
  73. if((file.substring(location).compareTo(extensions[n])) != 0)
  74. {
  75. compare = false;
  76. }
  77. else if((file.substring(location).compareTo(extensions[n])) == 0)
  78. {
  79. compare = true;
  80. }
  81. }
  82. return true;
  83. }
  84. public static String nameNewFile()
  85. {
  86. location = file.indexOf(".");
  87. newFile = file.substring(0, location);
  88. newFile = newFile + "(copy).txt";
  89. fileTwo = new File(newFile);
  90. return file;
  91. }
  92.  
  93. public static void CopyFile() throws IOException
  94. {
  95. Scanner read = new Scanner(filename);
  96. PrintWriter write = new PrintWriter(fileTwo);
  97. while(read.hasNextLine())
  98. {
  99. line = read.nextLine();
  100. write.println(line);
  101. }
  102. read.close();
  103. write.close(); //Saves file
  104. }
  105. }
Success #stdin #stdout 0.14s 321088KB
stdin
NumberList.txt
stdout
What file do you want to copy?(Include extension) Checking file
Finding file...
File existance: false