Question
First, examine the two programs ReadData and WriteData in the Chapter 12 Programs folder in Blackboard to get a full understanding on how data can
First, examine the two programs ReadData and WriteData in the Chapter 12 Programs folder in Blackboard to get a full understanding on how data can be read from a file, processed inside the program, and then written to a different file.
The program should:
Check to see if there are two arguments entered, and if not, send an error message to the console and exit.
(Hint: You can test this using args.length != 2.)
Check to see if the input file exists, and if not, send an error message to the console and then System.exit(0).
(Hint:You can test this using !inputFile.exists()
Using a Scanner object and while loops, you can read each line from the input file using the hasNext and nextLine methods. The lengths of all lines added together will give you the overall number of characters in the input file.
To test for the JAVA string, you can flip each line to upper case using the toUppercase method and use a Boolean to test to see if the line contains JAVA. You can use either the contains method in the String class to see if JAVA exists, or see if the index (e.g. indexOf method) is greater than or equal to 0.
Write a program that reads an input file of text, and writes the following to the output file:
name of the input file
the number of characters
the number of lines
whether the string java (upper or lower case characters) is contained in the input file.
The input and output file names should be passed as command line arguments to the program. In Netbeans, you can set the arguments by clicking on Run Set Project Configuration Customize, and enter the arguments. The two arguments are:
Lab10IP.txt for the input file name
Lab10OP.txt for the output file name
The program should:
Check to see if there are two arguments entered, and if not, send an error message to the console and exit.
(Hint: You can test this using args.length != 2.)
Check to see if the input file exists, and if not, send an error message to the console and then System.exit(0).
(Hint:You can test this using !inputFile.exists()
Using a Scanner object and while loops, you can read each line from the input file using the hasNext and nextLine methods. The lengths of all lines added together will give you the overall number of characters in the input file.
To test for the JAVA string, you can flip each line to upper case using the toUppercase method and use a Boolean to test to see if the line contains JAVA. You can use either the contains method in the String class to see if JAVA exists, or see if the index (e.g. indexOf method) is greater than or equal to 0.
CSC108- Introduction to Programming Lab 10 File I/O and Strings First, examine the two programs Read Data and WriteData in the Chapter 12 Programs folder in Blackboard to get a full understanding on how data can be read from a file, processed inside the program, and then written to a different file. Write a program that reads an input file of text, and writes the following to the output file: name of the input file the number of characters e the number of lines whether the string "java" (upper or lower case characters) is contained in the input file. The input and output file names should be passed as command line arguments to the program. In Netbeans, you can set the arguments by clicking on Run-Set Project Configuration-Customize, and enter the arguments. The two arguments are: Lab10IP.txt Lab100P.txt for the input file name for the output file name Project Properties- Lab 10 Sources Libraries Build Confguration: lefeult confg New... Delete Compling Runtime Platform: Project Patform Main Class Arguments Manage Platforms.. Deployment ab 10.Lab 10 ts Lab 101P.bit Lab 100P.tut The program should: Check to see if there are two arguments entered, and if not, send an error message to the console and exit. (Hint: You can test this using args.length !-2.) Check to see if the input file exists, and if not, send an error message to the console and then System.exit(0). (Hint: You can test this using linputFile.exists0 . Using a Scanner object and while loops, you can read each line from the input file using the hasNext and nextLine methods. The lengths of all lines added together will give you the overall number of characters in the input file. To test for the "JAVA" string, you can flip each line to upper case using the toUppercase method and use a Boolean to test to see if the line contains "JAVA". You can use either the "contains" method in the String class to see if "JAVA" exists, or see if the index (e.g. indexOf method) is greater than or equal to 0. Here is an example of what the input file and output file could contain: LablOIP.txt Lab10OP.txt Java is good for the soul File Lab10IP.txt has 23 characters 4 lines Java appears in the input file Zip the Labl0 folder with the input and output files included, and send it to me as an attachment in BlackboardStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started