Advertisement
Josif_tepe

Untitled

Mar 25th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import javax.annotation.processing.SupportedSourceVersion;
  2. import java.io.*;
  3. import java.util.logging.Filter;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args){
  8.         BufferedInputStream bis = null;
  9.         BufferedOutputStream bos = null;
  10.         try {
  11.             InputStream in = new FileInputStream("izvor.txt");
  12.              bis = new BufferedInputStream(in);
  13.             OutputStream out = new FileOutputStream("destinacija.txt");
  14.              bos = new BufferedOutputStream(out);
  15.  
  16.             byte[] b = new byte[bis.available()];
  17.             int at = 0;
  18.             for(int x = bis.read(); x != -1; x = bis.read()) {
  19.                 if(x == 10) {
  20.                     if(b[0] >= 48 && b[0] <= 57) {
  21.                         for(int j = 0; j < at; j++) {
  22.                             out.write(b[j]);
  23.                         }
  24.                         out.write(10);
  25.                     }
  26.                     at = 0;
  27.                 }
  28.                 else {
  29.                     b[at] = (byte) x;
  30.                     at++;
  31.                 }
  32.             }
  33.             if(b[0] >= 48 && b[0] <= 57) {
  34.                 for(int j = 0; j < at; j++) {
  35.                     out.write(b[j]);
  36.                 }
  37.             }
  38.             out.flush();
  39.         }
  40.         catch (IOException ex ){
  41.  
  42.         }
  43.         finally {
  44.             try {
  45.                 if(bis != null)
  46.                   bis.close();
  47.                 if(bos != null)
  48.                  bos.close();
  49.  
  50.             }
  51.             catch (IOException e) {
  52.  
  53.             }
  54.         }
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement