SlideShare a Scribd company logo
JavaCode for Sample Projects
                                                    I/O Functionality Project

Fish.java File

// Fish.java - This program reads names of fish from an input file and
// prints them to the user's screen.
// Input: fish.dat.
// Output: Names of fish.

import java.io.*; // Import class for file input.

public class Fish
{
         public static void main(String args[]) throws Exception
         {

                 // Declare variables here.

                 String fishName;

                 // Open input file.
                 FileReaderfr = new FileReader("fish.dat");

                 // CreateBufferedReader object.
                 BufferedReaderbr = new BufferedReader(fr);


I/O Functionality Project                                                       Page 1
// Write while loop that tests for EOF here.
                  while((fishName = br.readLine()) != null)
                           // Print fish name in body of loop.
                   {
                           fishName = br.readLine();
                           System.out.println(fishName);

                  }

                  br.close();
                  System.exit(0);
         } // End of main() method.

} // End of Fish class.




I/O Functionality Project                                        Page 2

More Related Content

Similar to Java Code For Sample Projects I/O

5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
DEVTYPE
 
File management
File managementFile management
File management
lalithambiga kamaraj
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
JayasankarPR2
 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
Rasan Samarasinghe
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
DHARUNESHBOOPATHY
 
Files in c
Files in cFiles in c
Files in c
TanujaA3
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
PragatiSutar4
 
What`s new in Java 7
What`s new in Java 7What`s new in Java 7
What`s new in Java 7
Georgian Micsa
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
Martijn Verburg
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
Gaurav Garg
 
JDBC
JDBCJDBC
Complete the following Java code such that it opens a file named Fruit.docx
Complete the following Java code such that it opens a file named Fruit.docxComplete the following Java code such that it opens a file named Fruit.docx
Complete the following Java code such that it opens a file named Fruit.docx
ljohn878
 
working with files
working with filesworking with files
working with files
SangeethaSasi1
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testability
John Sundell
 
6. chapter v
6. chapter v6. chapter v
6. chapter v
Chhom Karath
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
sangeeta borde
 
자바스터디 4
자바스터디 4자바스터디 4
자바스터디 4jangpd007
 

Similar to Java Code For Sample Projects I/O (20)

5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
 
File management
File managementFile management
File management
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Oop lecture9 12
Oop lecture9 12Oop lecture9 12
Oop lecture9 12
 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Files in c
Files in cFiles in c
Files in c
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
What`s new in Java 7
What`s new in Java 7What`s new in Java 7
What`s new in Java 7
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
JDBC
JDBCJDBC
JDBC
 
Complete the following Java code such that it opens a file named Fruit.docx
Complete the following Java code such that it opens a file named Fruit.docxComplete the following Java code such that it opens a file named Fruit.docx
Complete the following Java code such that it opens a file named Fruit.docx
 
working with files
working with filesworking with files
working with files
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testability
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
6. chapter v
6. chapter v6. chapter v
6. chapter v
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
자바스터디 4
자바스터디 4자바스터디 4
자바스터디 4
 

More from jwjablonski

Amazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and FormsAmazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and Formsjwjablonski
 
Study Skills Project
Study Skills ProjectStudy Skills Project
Study Skills Projectjwjablonski
 
Java Code for Sample Projects Loops
Java Code for Sample Projects LoopsJava Code for Sample Projects Loops
Java Code for Sample Projects Loopsjwjablonski
 
Java Code for Sample Projects Methods
Java Code for Sample Projects MethodsJava Code for Sample Projects Methods
Java Code for Sample Projects Methodsjwjablonski
 
Java Code for Sample Projects Inheritance
Java Code for Sample Projects InheritanceJava Code for Sample Projects Inheritance
Java Code for Sample Projects Inheritancejwjablonski
 
VBA Final Project
VBA Final ProjectVBA Final Project
VBA Final Projectjwjablonski
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projectsjwjablonski
 
Animal Shelter Database Presentation
Animal Shelter Database PresentationAnimal Shelter Database Presentation
Animal Shelter Database Presentationjwjablonski
 

More from jwjablonski (11)

Portfolio
PortfolioPortfolio
Portfolio
 
Amazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and FormsAmazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and Forms
 
Study Skills Project
Study Skills ProjectStudy Skills Project
Study Skills Project
 
Java Code for Sample Projects Loops
Java Code for Sample Projects LoopsJava Code for Sample Projects Loops
Java Code for Sample Projects Loops
 
Java Code for Sample Projects Methods
Java Code for Sample Projects MethodsJava Code for Sample Projects Methods
Java Code for Sample Projects Methods
 
Java Code for Sample Projects Inheritance
Java Code for Sample Projects InheritanceJava Code for Sample Projects Inheritance
Java Code for Sample Projects Inheritance
 
VBA Final Project
VBA Final ProjectVBA Final Project
VBA Final Project
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
 
Animal Shelter Database Presentation
Animal Shelter Database PresentationAnimal Shelter Database Presentation
Animal Shelter Database Presentation
 
Hangman Program
Hangman ProgramHangman Program
Hangman Program
 
Cents Add Up
Cents Add Up Cents Add Up
Cents Add Up
 

Java Code For Sample Projects I/O

  • 1. JavaCode for Sample Projects I/O Functionality Project Fish.java File // Fish.java - This program reads names of fish from an input file and // prints them to the user's screen. // Input: fish.dat. // Output: Names of fish. import java.io.*; // Import class for file input. public class Fish { public static void main(String args[]) throws Exception { // Declare variables here. String fishName; // Open input file. FileReaderfr = new FileReader("fish.dat"); // CreateBufferedReader object. BufferedReaderbr = new BufferedReader(fr); I/O Functionality Project Page 1
  • 2. // Write while loop that tests for EOF here. while((fishName = br.readLine()) != null) // Print fish name in body of loop. { fishName = br.readLine(); System.out.println(fishName); } br.close(); System.exit(0); } // End of main() method. } // End of Fish class. I/O Functionality Project Page 2