Showing posts with label Read text file. Show all posts
Showing posts with label Read text file. Show all posts

Saturday, 7 May 2022

Read text file

             public String readFile(String filePath) throws IOException {

File file = new File(filePath);


BufferedReader br = new BufferedReader(new FileReader(file));


String st;

                String stringOutput="";

while ((st = br.readLine()) != null) {

stringOutput = stringOutput +st;

}

return stringOutput;

}

Switch case in Java

 Problem statement: Return the capital of a state based on input state          public String getCapital(String state){               switch...