Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package JavaIO;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.RandomAccessFile;
  7.  
  8. public class Juni2014 {
  9.  
  10. public static void manage (String in,String out) throws IOException {
  11.  
  12. File sourceFolder = new File(in);
  13. File destinationFolder = new File(out);
  14.  
  15. if (!sourceFolder.exists()) {
  16. System.out.println("Ne postoi" + in);
  17. }
  18. else {
  19. if(!sourceFolder.isDirectory()) {
  20. System.out.println(in + "Ne e direktorium");
  21. } else {
  22. if(destinationFolder.exists())
  23. {
  24. if(destinationFolder.isDirectory()) {
  25. File[] lista = destinationFolder.listFiles();
  26. for (File fajl : lista)
  27. fajl.delete();
  28.  
  29. } else {
  30. System.out.println(out + "Ne e direktorium");
  31. return;
  32. }
  33. }
  34. else
  35. destinationFolder.mkdirs();
  36.  
  37. File[] lista = sourceFolder.listFiles();
  38.  
  39. for (File f : lista) {
  40.  
  41. if(f.getName().endsWith(".dat")) {
  42.  
  43. if(f.isHidden()) {
  44. f.delete();
  45. System.out.println("Zbunet sum " + f.getAbsolutePath());
  46. } else {
  47. if(f.canWrite()) {
  48. System.out.println("Pomestuvam " + f.getAbsolutePath());
  49. f.renameTo(new File(destinationFolder,f.getName()));
  50. }
  51.  
  52. else {
  53. File zaPisuvanje = new File("resources/writible-content.txt");
  54. readFromSourceAppendToDestination(f,zaPisuvanje);
  55. System.out.println("Dopisuvam " + f.getAbsolutePath());
  56. }
  57. }
  58. }
  59. }
  60.  
  61. }
  62. }
  63. }
  64.  
  65. private static void readFromSourceAppendToDestination(File source,File destination) throws IOException {
  66. // TODO Auto-generated method stub
  67.  
  68. RandomAccessFile vlez = null;
  69. RandomAccessFile izlez = null;
  70.  
  71. try {
  72. vlez = new RandomAccessFile(source,"r");
  73. izlez = new RandomAccessFile(destination, "rw");
  74.  
  75. izlez.seek(izlez.length());
  76.  
  77. int b;
  78.  
  79. while ((b = vlez.read()) != -1)
  80. izlez.write(b);
  81. }
  82. finally {
  83.  
  84. if(izlez != null){
  85. izlez.close();
  86. }
  87. if(vlez != null) {
  88. vlez.close();
  89. }
  90. }
  91. }
  92.  
  93. public static void main(String[] args) throws IOException {
  94. // TODO Auto-generated method stub
  95. manage("in","out");
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement