Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.File;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class HW01_2 {
- public static void writeFile(File source, File destination) throws IOException {
- RandomAccessFile reader = null;
- RandomAccessFile writer = null;
- try{
- reader = new RandomAccessFile(source, "r");
- writer = new RandomAccessFile(destination, "rw");
- for(long i=reader.length()-1;i>=0;i--){
- reader.seek(i);
- int c = reader.read();
- writer.write(c);
- }
- }
- catch (Exception e){}
- finally {
- if (reader != null){
- reader.close();
- }
- if(writer != null){
- writer.close();
- }
- }
- }
- public static void main(String[] args) throws IOException {
- // write your code here
- File source = new File("C:\\Users\\Ivana\\Downloads\\OSprimeri\\izvor.txt");
- File destination = new File("C:\\Users\\Ivana\\Downloads\\OSprimeri\\destinacija.txt");
- writeFile(source,destination);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement