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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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