Advertisement
Martina312

Untitled

Mar 18th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class IOStreams {
  4.     public static boolean checkIfNumber(String line){
  5.          if(Character.isDigit(line.charAt(0)))
  6.              return true;
  7.          else return false;
  8.     }
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader br=null;
  12.         BufferedWriter bw=null;
  13.         try {
  14.             br = new BufferedReader(new InputStreamReader(new FileInputStream("izvor.txt")));
  15.             bw = new BufferedWriter(new FileWriter("destinacija.txt"));
  16.  
  17.             String line = null;
  18.             while (true) {
  19.                 line = br.readLine();
  20.                 if (line == null)
  21.                     break;
  22.  
  23.                 if (checkIfNumber(line)) {
  24.                     bw.write(line + "\n");
  25.                 }
  26.             }
  27.         }finally {
  28.             if(br!=null){
  29.                 br.close();
  30.             }
  31.             if(bw!=null){
  32.                 bw.flush();
  33.                 bw.close();
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement