SlideShare una empresa de Scribd logo
1 de 3
JAVA
Q2: Write a program that reads strings from the user and writes them to an output file called
userStrings.txt. Stop processing when the user enters the string "DONE". Do not write the
sentinel string ("DONE") to the output file. [15 points] Hint: For a complete example of file IO,
please see the attached TestData program.
Sample Output:
A string.
Another string.
Yet more text...
DONE
Solution
Answer
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
class WriteStringFile {
public static void main(String[] args) {
File file = new File("D:/userFile.txt");
String data;
Scanner input = new Scanner(System.in);
data = input.readLine();
try (FileOutputStream fop = new FileOutputStream(file)) {
// if file doesn't exists, then create it
if (!file.exists()) {
file.createNewFile();
}
if (data != "DONE") {
// get the content in bytes
byte[] contentInBytes = content.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
} else {
System.out.println("User Enter the value Done.. So unable to write into file");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
JAVA Q2- Write a program that reads strings from the user and writes t.docx

Más contenido relacionado

Similar a JAVA Q2- Write a program that reads strings from the user and writes t.docx

Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntuKhurshid Asghar
 
• GUI design using drag and drop feature of IDE(Net beans), • File IO
•	GUI design using drag and drop feature of IDE(Net beans), •	File IO•	GUI design using drag and drop feature of IDE(Net beans), •	File IO
• GUI design using drag and drop feature of IDE(Net beans), • File IOSyedShahroseSohail
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfatulkapoor33
 
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.docxhamblymarta
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12Vince Vo
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdff3apparelsonline
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsDon Bosco BSIT
 
In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfsuresh640714
 
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.pdfrbjain2007
 
The java program that reads an input file input.txt an.pdf
   The java program that reads an input file input.txt  an.pdf   The java program that reads an input file input.txt  an.pdf
The java program that reads an input file input.txt an.pdfvichu19891
 

Similar a JAVA Q2- Write a program that reads strings from the user and writes t.docx (20)

Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
 
Bhaloo
BhalooBhaloo
Bhaloo
 
CORE JAVA-1
CORE JAVA-1CORE JAVA-1
CORE JAVA-1
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
• GUI design using drag and drop feature of IDE(Net beans), • File IO
•	GUI design using drag and drop feature of IDE(Net beans), •	File IO•	GUI design using drag and drop feature of IDE(Net beans), •	File IO
• GUI design using drag and drop feature of IDE(Net beans), • File IO
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
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
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
 
In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdf
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
 
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
 
The java program that reads an input file input.txt an.pdf
   The java program that reads an input file input.txt  an.pdf   The java program that reads an input file input.txt  an.pdf
The java program that reads an input file input.txt an.pdf
 

Más de michael1810

Judging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxJudging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxmichael1810
 
John Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxJohn Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxmichael1810
 
John Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxJohn Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxmichael1810
 
John has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxJohn has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxmichael1810
 
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxJoe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxmichael1810
 
Java Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxJava Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxmichael1810
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxmichael1810
 
Java Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxJava Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxmichael1810
 
It-'s virtualization topic Would anyone please expalin what is the di.docx
It-'s virtualization topic  Would anyone please expalin what is the di.docxIt-'s virtualization topic  Would anyone please expalin what is the di.docx
It-'s virtualization topic Would anyone please expalin what is the di.docxmichael1810
 
For each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxFor each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxmichael1810
 
For each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxFor each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxmichael1810
 
For Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxFor Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxmichael1810
 
For each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxFor each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxmichael1810
 
For each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxFor each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxmichael1810
 
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxFluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxmichael1810
 
Fluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxFluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxmichael1810
 
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxFirst National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxmichael1810
 

Más de michael1810 (17)

Judging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxJudging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docx
 
John Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxJohn Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docx
 
John Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxJohn Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docx
 
John has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxJohn has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docx
 
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxJoe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
 
Java Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxJava Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docx
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docx
 
Java Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxJava Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docx
 
It-'s virtualization topic Would anyone please expalin what is the di.docx
It-'s virtualization topic  Would anyone please expalin what is the di.docxIt-'s virtualization topic  Would anyone please expalin what is the di.docx
It-'s virtualization topic Would anyone please expalin what is the di.docx
 
For each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxFor each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docx
 
For each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxFor each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docx
 
For Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxFor Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docx
 
For each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxFor each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docx
 
For each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxFor each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docx
 
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxFluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
 
Fluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxFluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docx
 
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxFirst National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
 

Último

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Último (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

JAVA Q2- Write a program that reads strings from the user and writes t.docx

  • 1. JAVA Q2: Write a program that reads strings from the user and writes them to an output file called userStrings.txt. Stop processing when the user enters the string "DONE". Do not write the sentinel string ("DONE") to the output file. [15 points] Hint: For a complete example of file IO, please see the attached TestData program. Sample Output: A string. Another string. Yet more text... DONE Solution Answer import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; class WriteStringFile { public static void main(String[] args) { File file = new File("D:/userFile.txt"); String data;
  • 2. Scanner input = new Scanner(System.in); data = input.readLine(); try (FileOutputStream fop = new FileOutputStream(file)) { // if file doesn't exists, then create it if (!file.exists()) { file.createNewFile(); } if (data != "DONE") { // get the content in bytes byte[] contentInBytes = content.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); } else { System.out.println("User Enter the value Done.. So unable to write into file"); } } catch (IOException e) { e.printStackTrace(); } } }