DisplayBook.java import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; public class DisplayBook { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); File file = new File(\"D:\\\\books.txt\"); if(file.exists()){ System.out.println(\"File exists\"); FileInputStream fis = new FileInputStream(file); int content; while ((content = fis.read()) != -1) { System.out.print((char) content); } fis.close(); } else{ System.out.println(\"File does not exist\"); String titles = \"\"; FileOutputStream fop = new FileOutputStream(file); while(true){ System.out.println(\"Enter Book Title (none to exit):\"); String title = scan.nextLine(); if(title.equalsIgnoreCase(\"none\")){ break; } else{ titles = titles + title +\"\ \"; } } byte[] contentInBytes = titles.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); } } } Output: File does not exist Enter Book Title (none to exit): Physics Enter Book Title (none to exit): Chemistry Enter Book Title (none to exit): Science Enter Book Title (none to exit): Maths Enter Book Title (none to exit): none -------------------------------------- File exists Physics Chemistry Science Maths Solution DisplayBook.java import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; public class DisplayBook { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); File file = new File(\"D:\\\\books.txt\"); if(file.exists()){ System.out.println(\"File exists\"); FileInputStream fis = new FileInputStream(file); int content; while ((content = fis.read()) != -1) { System.out.print((char) content); } fis.close(); } else{ System.out.println(\"File does not exist\"); String titles = \"\"; FileOutputStream fop = new FileOutputStream(file); while(true){ System.out.println(\"Enter Book Title (none to exit):\"); String title = scan.nextLine(); if(title.equalsIgnoreCase(\"none\")){ break; } else{ titles = titles + title +\"\ \"; } } byte[] contentInBytes = titles.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); } } } Output: File does not exist Enter Book Title (none to exit): Physics Enter Book Title (none to exit): Chemistry Enter Book Title (none to exit): Science Enter Book Title (none to exit): Maths Enter Book Title (none to exit): none -------------------------------------- File exists Physics Chemistry Science Maths.