Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package ppj28;
  2. import java.io.*;
  3. import java.io.FileReader;
  4.  
  5.  
  6. public class CodeFormeter {
  7.     public static void main(String[] args) {
  8.         File file = new File("C:\\Users\\s15678\\Desktop\\Ppj12.java");
  9.         FileReader fis = null;
  10.         StringBuffer output = new StringBuffer();
  11.         try {
  12.              fis = new FileReader(file);
  13.             int tmp ;
  14.             while((tmp=fis.read())!=-1){
  15.                 output.append((char)tmp);  
  16.             }          
  17.            
  18.         } catch (FileNotFoundException e) {
  19.             e.printStackTrace();
  20.         }catch(IOException e){
  21.             e.printStackTrace();
  22.         }finally{
  23.             try{
  24.                 if(fis!=null){
  25.                     fis.close();
  26.                 }
  27.             }catch(IOException ex){
  28.                 ex.printStackTrace();
  29.             }
  30.        }
  31.        
  32.         System.out.println(output);
  33.         String outp  = output.toString();
  34.         try{
  35.             FileWriter fW = new FileWriter("C:\\Users\\s15678\\Desktop\\Ppj12_copy.java");
  36.            
  37.             for (int i = 0; i < outp.length(); i++) {
  38.                 if (outp.charAt(i)=='{') {
  39.                     fW.write(outp.charAt(i)+"\n"+"\t");
  40.                 } else
  41.                 fW.write(outp.charAt(i));
  42.             }
  43.            
  44.             fW.close();
  45.         }catch(Exception e){
  46.             e.printStackTrace();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement