SlideShare a Scribd company logo
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

More Related Content

Similar to DisplayBook.java import java.io.File; import java.io.FileInput.pdf

Lab4
Lab4Lab4
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
anjanacottonmills
 
2. Write a program which will open an input file and write to an out.pdf
2. Write a program which will open an input file and write to an out.pdf2. Write a program which will open an input file and write to an out.pdf
2. Write a program which will open an input file and write to an out.pdf
rbjain2007
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docx
hamblymarta
 
5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
DEVTYPE
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12Vince Vo
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
Kavitha713564
 
File Input and Output in Java Programing language
File Input and Output in Java Programing languageFile Input and Output in Java Programing language
File Input and Output in Java Programing language
BurhanKhan774154
 
Know how to redirect input and output- and know how to append to an ex.docx
Know how to redirect input and output- and know how to append to an ex.docxKnow how to redirect input and output- and know how to append to an ex.docx
Know how to redirect input and output- and know how to append to an ex.docx
wkelli
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
secunderbadtirumalgi
 
FileHandling.docx
FileHandling.docxFileHandling.docx
FileHandling.docx
NavneetSheoran3
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
ajoy21
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
noreendchesterton753
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
SudhanshiBakre1
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
PragatiSutar4
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
Danairat Thanabodithammachari
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
ESUG
 

Similar to DisplayBook.java import java.io.File; import java.io.FileInput.pdf (20)

Lab4
Lab4Lab4
Lab4
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
 
2. Write a program which will open an input file and write to an out.pdf
2. Write a program which will open an input file and write to an out.pdf2. Write a program which will open an input file and write to an out.pdf
2. Write a program which will open an input file and write to an out.pdf
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docx
 
5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
 
26 io -ii file handling
26  io -ii  file handling26  io -ii  file handling
26 io -ii file handling
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
File Input and Output in Java Programing language
File Input and Output in Java Programing languageFile Input and Output in Java Programing language
File Input and Output in Java Programing language
 
Know how to redirect input and output- and know how to append to an ex.docx
Know how to redirect input and output- and know how to append to an ex.docxKnow how to redirect input and output- and know how to append to an ex.docx
Know how to redirect input and output- and know how to append to an ex.docx
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
FileHandling.docx
FileHandling.docxFileHandling.docx
FileHandling.docx
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 

More from sudheerforce

the bond between Si and O .pdf
                     the bond between Si and O                        .pdf                     the bond between Si and O                        .pdf
the bond between Si and O .pdf
sudheerforce
 
Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
                     Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf                     Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
sudheerforce
 
step 1 Br2 under UV light step 2 NMe3 Solu.pdf
                     step 1 Br2 under UV light step 2 NMe3  Solu.pdf                     step 1 Br2 under UV light step 2 NMe3  Solu.pdf
step 1 Br2 under UV light step 2 NMe3 Solu.pdf
sudheerforce
 
Since column chromatography substances are separa.pdf
                     Since column chromatography substances are separa.pdf                     Since column chromatography substances are separa.pdf
Since column chromatography substances are separa.pdf
sudheerforce
 
Option III .pdf
                     Option III                                      .pdf                     Option III                                      .pdf
Option III .pdf
sudheerforce
 
Oh group is removed by Br yes ther can be two ty.pdf
                     Oh group is removed by Br  yes ther can be two ty.pdf                     Oh group is removed by Br  yes ther can be two ty.pdf
Oh group is removed by Br yes ther can be two ty.pdf
sudheerforce
 
Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
                     Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf                     Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
sudheerforce
 
Is this a reduction oxidation reaction If so, wh.pdf
                     Is this a reduction oxidation reaction If so, wh.pdf                     Is this a reduction oxidation reaction If so, wh.pdf
Is this a reduction oxidation reaction If so, wh.pdf
sudheerforce
 
HNO3========= H+ (aq) + NO3-(aq) [H+] = 0.0578 .pdf
                     HNO3========= H+ (aq) + NO3-(aq)  [H+] = 0.0578 .pdf                     HNO3========= H+ (aq) + NO3-(aq)  [H+] = 0.0578 .pdf
HNO3========= H+ (aq) + NO3-(aq) [H+] = 0.0578 .pdf
sudheerforce
 
Valley fever is the initial form of coccidioidomycosis infection. Th.pdf
Valley fever is the initial form of coccidioidomycosis infection. Th.pdfValley fever is the initial form of coccidioidomycosis infection. Th.pdf
Valley fever is the initial form of coccidioidomycosis infection. Th.pdf
sudheerforce
 
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdf
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdfYes,The interthalamic adhesion (also known as the mass intermedia or.pdf
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdf
sudheerforce
 
Think of the X and Y as totally different events. The expected value.pdf
Think of the X and Y as totally different events. The expected value.pdfThink of the X and Y as totally different events. The expected value.pdf
Think of the X and Y as totally different events. The expected value.pdf
sudheerforce
 
There are two source terms in Maxwell’s equations, the static charge.pdf
There are two source terms in Maxwell’s equations, the static charge.pdfThere are two source terms in Maxwell’s equations, the static charge.pdf
There are two source terms in Maxwell’s equations, the static charge.pdf
sudheerforce
 
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdfThe xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
sudheerforce
 
The strengths of the Indian Parliamentary System of governanace1..pdf
The strengths of the Indian Parliamentary System of governanace1..pdfThe strengths of the Indian Parliamentary System of governanace1..pdf
The strengths of the Indian Parliamentary System of governanace1..pdf
sudheerforce
 
Pulse code modulationPulse code modulation is a digital sign of a.pdf
Pulse code modulationPulse code modulation is a digital sign of a.pdfPulse code modulationPulse code modulation is a digital sign of a.pdf
Pulse code modulationPulse code modulation is a digital sign of a.pdf
sudheerforce
 
PFA JAVA programimport java.io.; import java.util.; import .pdf
PFA JAVA programimport java.io.; import java.util.; import .pdfPFA JAVA programimport java.io.; import java.util.; import .pdf
PFA JAVA programimport java.io.; import java.util.; import .pdf
sudheerforce
 
D) four s bonds Pi bonds are double bonds as carb.pdf
                     D) four s bonds Pi bonds are double bonds as carb.pdf                     D) four s bonds Pi bonds are double bonds as carb.pdf
D) four s bonds Pi bonds are double bonds as carb.pdf
sudheerforce
 
out of Africa hypothesis out of Africa hypothesis is about .pdf
out of Africa hypothesis out of Africa hypothesis is about .pdfout of Africa hypothesis out of Africa hypothesis is about .pdf
out of Africa hypothesis out of Africa hypothesis is about .pdf
sudheerforce
 
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdfLeukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
sudheerforce
 

More from sudheerforce (20)

the bond between Si and O .pdf
                     the bond between Si and O                        .pdf                     the bond between Si and O                        .pdf
the bond between Si and O .pdf
 
Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
                     Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf                     Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
Step1 Equivalents of NaOH= .1146 x[19.25-.55]x10^.pdf
 
step 1 Br2 under UV light step 2 NMe3 Solu.pdf
                     step 1 Br2 under UV light step 2 NMe3  Solu.pdf                     step 1 Br2 under UV light step 2 NMe3  Solu.pdf
step 1 Br2 under UV light step 2 NMe3 Solu.pdf
 
Since column chromatography substances are separa.pdf
                     Since column chromatography substances are separa.pdf                     Since column chromatography substances are separa.pdf
Since column chromatography substances are separa.pdf
 
Option III .pdf
                     Option III                                      .pdf                     Option III                                      .pdf
Option III .pdf
 
Oh group is removed by Br yes ther can be two ty.pdf
                     Oh group is removed by Br  yes ther can be two ty.pdf                     Oh group is removed by Br  yes ther can be two ty.pdf
Oh group is removed by Br yes ther can be two ty.pdf
 
Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
                     Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf                     Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
Moles of Na2O2 = 2578=0.32 Moles of H2O = 12.11.pdf
 
Is this a reduction oxidation reaction If so, wh.pdf
                     Is this a reduction oxidation reaction If so, wh.pdf                     Is this a reduction oxidation reaction If so, wh.pdf
Is this a reduction oxidation reaction If so, wh.pdf
 
HNO3========= H+ (aq) + NO3-(aq) [H+] = 0.0578 .pdf
                     HNO3========= H+ (aq) + NO3-(aq)  [H+] = 0.0578 .pdf                     HNO3========= H+ (aq) + NO3-(aq)  [H+] = 0.0578 .pdf
HNO3========= H+ (aq) + NO3-(aq) [H+] = 0.0578 .pdf
 
Valley fever is the initial form of coccidioidomycosis infection. Th.pdf
Valley fever is the initial form of coccidioidomycosis infection. Th.pdfValley fever is the initial form of coccidioidomycosis infection. Th.pdf
Valley fever is the initial form of coccidioidomycosis infection. Th.pdf
 
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdf
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdfYes,The interthalamic adhesion (also known as the mass intermedia or.pdf
Yes,The interthalamic adhesion (also known as the mass intermedia or.pdf
 
Think of the X and Y as totally different events. The expected value.pdf
Think of the X and Y as totally different events. The expected value.pdfThink of the X and Y as totally different events. The expected value.pdf
Think of the X and Y as totally different events. The expected value.pdf
 
There are two source terms in Maxwell’s equations, the static charge.pdf
There are two source terms in Maxwell’s equations, the static charge.pdfThere are two source terms in Maxwell’s equations, the static charge.pdf
There are two source terms in Maxwell’s equations, the static charge.pdf
 
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdfThe xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
The xenate ion, [HXeO4]-, slowly decomposes in alkaline solution to .pdf
 
The strengths of the Indian Parliamentary System of governanace1..pdf
The strengths of the Indian Parliamentary System of governanace1..pdfThe strengths of the Indian Parliamentary System of governanace1..pdf
The strengths of the Indian Parliamentary System of governanace1..pdf
 
Pulse code modulationPulse code modulation is a digital sign of a.pdf
Pulse code modulationPulse code modulation is a digital sign of a.pdfPulse code modulationPulse code modulation is a digital sign of a.pdf
Pulse code modulationPulse code modulation is a digital sign of a.pdf
 
PFA JAVA programimport java.io.; import java.util.; import .pdf
PFA JAVA programimport java.io.; import java.util.; import .pdfPFA JAVA programimport java.io.; import java.util.; import .pdf
PFA JAVA programimport java.io.; import java.util.; import .pdf
 
D) four s bonds Pi bonds are double bonds as carb.pdf
                     D) four s bonds Pi bonds are double bonds as carb.pdf                     D) four s bonds Pi bonds are double bonds as carb.pdf
D) four s bonds Pi bonds are double bonds as carb.pdf
 
out of Africa hypothesis out of Africa hypothesis is about .pdf
out of Africa hypothesis out of Africa hypothesis is about .pdfout of Africa hypothesis out of Africa hypothesis is about .pdf
out of Africa hypothesis out of Africa hypothesis is about .pdf
 
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdfLeukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
Leukocytes or WBC They are of two typesGranulocytes Neutrophils.pdf
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 

DisplayBook.java import java.io.File; import java.io.FileInput.pdf

  • 1. 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 +" "; }
  • 2. } 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;
  • 3. 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(); }
  • 4. } } 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