Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.RandomAccessFile;
  6.  
  7. public class HW01_2 {
  8.  
  9. public static void writeFile(File source, File destination) throws IOException {
  10. RandomAccessFile reader = null;
  11. RandomAccessFile writer = null;
  12.  
  13. try{
  14. reader = new RandomAccessFile(source, "r");
  15. writer = new RandomAccessFile(destination, "rw");
  16.  
  17.  
  18. for(long i=reader.length()-1;i>=0;i--){
  19. reader.seek(i);
  20. int c = reader.read();
  21. writer.write(c);
  22. }
  23.  
  24. }
  25. catch (Exception e){}
  26. finally {
  27. if (reader != null){
  28. reader.close();
  29. }
  30. if(writer != null){
  31. writer.close();
  32. }
  33. }
  34. }
  35.  
  36.  
  37. public static void main(String[] args) throws IOException {
  38. // write your code here
  39. File source = new File("C:\\Users\\Ivana\\Downloads\\OSprimeri\\izvor.txt");
  40. File destination = new File("C:\\Users\\Ivana\\Downloads\\OSprimeri\\destinacija.txt");
  41.  
  42. writeFile(source,destination);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement