Andziev

HW01_2

Mar 12th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5.  
  6. public class HW01_2 {
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.         FileInputStream input = null;
  10.         FileOutputStream output = null;
  11.  
  12.         try {
  13.             input = new FileInputStream("izvor.txt");
  14.             output = new FileOutputStream("destinacija.txt");
  15.  
  16.             int key;
  17.             StringBuilder sb = new StringBuilder();
  18.  
  19.             while ((key = input.read()) != -1) {
  20.                 sb.append((char) key);
  21.             }
  22.  
  23.             for (byte b : sb.reverse().toString().getBytes()) {
  24.                 output.write(b);
  25.             }
  26.         } catch (FileNotFoundException e) {
  27.  
  28.         } finally {
  29.             try {
  30.                 input.close();
  31.                 output.close();
  32.             } catch (IOException e) {
  33.  
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment