Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Sunday, 24 September 2017

Java program to access a file and align the lines properly

import java.io.BufferedReader;



import java.io.FileReader;

import java.util.Scanner;

public class Strins {

private static BufferedReader br;


public static void main(String[] args) throws Exception

{

String line=null;

String input=null;

       Scanner sc =new Scanner(System.in);

try {

System.out.println("enter the path");

input=sc.nextLine();

FileReader fr=new FileReader(input);

   

  br = new BufferedReader(fr);

  while(( line=br.readLine()) != null)

  {

 

       char []ch1=line.toCharArray();

       for(int i=0;i<ch1.length;i++)

       {

        System.out.print(ch1[i]);

         if(ch1[i]==';'||ch1[i]=='}'||ch1[i]=='{')

       {

       System.out.println();

       }

       }

}

}catch(Exception e){System.out.println(e);}

}

}




1 comment: