Managing error handling and files

Assignment Help JAVA Programming
Reference no: EM131588685

Managing Error Handling and Files

Before you attempt this section, review the concept of Files from your text book. Double-Click on the IDE (Eclipse or Java Beans) on your desktop as directed by your Instructor. Once you launch your IDE, close the WELCOME page. You are now ready to follow the instructions below:
We are going to use PROGFIVE to read data from a file and then write data to a file. Note that file is read to a BufferedReader. We also need to set the filename to a value. Before, you start your coding, you need to create a file with text and store it in documents in the virtual lab. Type the following in the text file using Notepad.
It is a wonder day at Ashford University. I am in this class to learn Java and more precisely, how to use file. If I am working with files, I have completed 4 previous programs. I am not sure if it has been fun but it has been interesting.

Save the file as myfile.txt
Open Eclipse as you have done in the past and start coding. Create a new project called PROGFIVE and within the project create a class called testfiles (remember right click on src). The code below has minor errors that you will have to fix on your own. The errors are intentional. Also, do not just copy this code, try to rewrite using classes and methods.
Start a Java project

import java.io.*; //needed to handle files

public class testFiles {

public static void main(String[] args) {

String fileName = "myfile.txt"; //you need to include the full file path in between " "

// This will reference one line at a time

String line = null;

//below is the error handling if the file does not exist

try {

System.out.println("place your name here");

FileReader fileReader = new FileReader(fileName);

BufferedReader bufferedReader = new BufferedReader(fileReader);

while((line = bufferedReader.readLine()) != null) {

System.out.println(line)

}

bufferedReader.close(); //closing file after processing

}

//error if the file does not exits

catch(FileNotFoundException ex) {

System.out.println("Unable to open file ‘');

}

catch(IOException ex) {

System.out.println( "Error reading file ")

}

}

}

Now you are ready to run your code.

Reference no: EM131588685

Questions Cloud

Create a program that accepts a 10-digit phone number : Create a program that accepts a 10-digit phone number (no 1 in front) and tells the user if the message is a toll-free number.
Determining the understanding structure : Write pseudocode that describes the process of guessing a number between 1 and 100. After each guess, you should tell the player whether the guess.
How might this have influenced his behavior : Try to "connect the dots" between what was happening at Arthur Andersen and Enron, and discuss how each business entity's set of events was separate
What are the differences between a z-test and an anova : What are the differences between an independent t-test, a dependent t-test, a z-test, an ANOVA, an ANCOVA?
Managing error handling and files : review the concept of Files from your text book. Double-Click on the IDE (Eclipse or Java Beans) on your desktop as directed by your Instructor
Why the lease meets the capital lease requirements : Please write a memo to your boss (me) discussing the reason why the lease meets the capital lease requirements
Discusses four types of perceptual distortions : Discusses four types of perceptual distortions- stereotyping, halo effects, selective perception, and projection. Define each of these and provide an example
Create a sexual harassment policy : Create a sexual harassment policy for your selected company to address a sexual harassment complaint.
Describe the types of computer hardware : For this essay, describe the types of computer hardware and software your employees will use, the type of network setup you will need between the two offices

Reviews

Write a Review

JAVA Programming Questions & Answers

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date. Throughout the code, comments and/or relevant component names should attempt to make the program understandable.

  The application with all the specifications should be

the application with all the specifications should be developed based on a graphical user interface.1. implement proper

  Personalize the time zone application of section 24.3

Personalize the time zone application of Section 24.3. Prompt the user to log in and specify a city to be stored in a profile. The next time the user logs in, the time of their favorite city is displayed automatically.

  Write a java program to demonstrate the singleton pattern

Write a Java program (non-GUI i.e only Java class) to demonstrate the Singleton pattern.The key parts of the singleton pattern are:A private static variable to store the single instance called the singleton.A public static method for callers to get a..

  Create a console program that prompts the user

Create a console program that prompts the user to enter the name and address of their employer and position they hold or the name and address of their favorite restaurant and their favorite meal.Display this information on the screen, each on a se..

  Create a menu-driven program that accept collection integers

Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen.

  Create a japplet that contains two parallel arrays

Create a "JApplet" that contains two parallel arrays with at least five friends' names and phone numbers. Allow the user to enter either a name or phone number and to click a "JButton" to display the other.

  Create a whole different set of variables

I am asked to generate a set of INPUT TEST VALUES. Is that included into this control structure, or do I have to create a whole different set of variables?

  Details of all advertisers registered with the service

Create a list of 6-7 different customers of both types with made-up details built in to the client program - display the details of all advertisers registered with the service,

  Implement a javascript program for the validation case

Write a JavaScript program for the validation case using the RegExp method - implement a JavaScript program for the validation case

  Write a void function this passed three integers

1. Write a void function this passed three integers by reference. The function should rearrange the parameter values so that the first parameter will get the smallest value; the second parameter the middle value; and the third parameter the largest v..

  In light of wrestling with ethics

In light of "Wrestling With Ethics" and other research/articles that you are able to draw upon, should profitability drive social responsibility? Be sure to support your discussion question responses with evidence from the readings and/or additional ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd