Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

FILE IO IN JAVA AND ITS DETAIL DESCRIPTION, Thesis of Java Programming

This Files gives the detail information of the File IO in java so using these 3 pdf u can claer the concepts of your file NIO

Typology: Thesis

2016/2017

Uploaded on 11/25/2017

krutarth-ganatra
krutarth-ganatra 🇮🇳

3 documents

1 / 33

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Streams and Input/Output Files
Part I
Chapter-07
Mohammed Husain Bohara
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download FILE IO IN JAVA AND ITS DETAIL DESCRIPTION and more Thesis Java Programming in PDF only on Docsity!

Streams and Input/Output Files

Part I

Chapter- 07

Mohammed Husain Bohara

Streams & Files

The objectives of this chapter are:

To understand the principles of I/O

streams and where to use them

To understand the options and limitations

of I/O streams

To become comfortable with the

mechanisms for accessing the file system

Limitation

 The data is lost when variable goes out of

scope or when the program terminates.

That is data is stored in temporary/mail

memory is released when program

terminates.

 It is difficult to handle large volumes of

data.

Solution

 We can overcome this problem by storing

data on secondary storage devices such

as floppy or hard disks.

 The data is stored in these devices using

the concept of Files and such data is

often called persistent data.

C Input/Output Revision

FILE* fp;

fp = fopen(“In.file”, “rw”);

fscanf(fp, ……);

frpintf(fp, …..);

fread(………, fp);

fwrite(……….., fp);

Java Application Requirement

abc.txt Java Application xyz.txt

FIS

read

FOS

write

Will it Compile or not

javap java.io.FileInputStream

Output

 Data will be copied successfully

What will be the output here?

import java.io.*;

class FileIOExample

{

public static void main(String[] args) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream("abc.txt"); FileOutputStream fos = new FileOutputStream("xyz.txt"); int c; while((c=fis.read())!=-1) { System.out.println(c); fos.write(c); } fis.close(); fos.close(); }

}

I/O and Data Movement

 The flow of data into a program

(input) may come from different

devices such as keyboard,

mouse, memory, disk, network,

or another program.

 The flow of data out of a

program (output) may go to the

screen, printer, memory, disk,

network, another program.

 Both input and output share a

certain common property such as

unidirectional movement of data

  • a sequence of bytes and

characters and support to the

sequential access to the data.

Streams

 Java Uses the concept of

Streams to represent the

ordered sequence of data, a

common characteristic shared

by all I/O devices.

 Streams presents a uniform,

easy to use, object oriented

interface between the

program and I/O devices.

 A stream in Java is a path

along which data flows (like a

river or pipe along which

water flows).

Java Stream Classes

 Input/Output related classes are defined in

java.io package.

 Input/Output in Java is defined in terms of

streams.

 A stream is a sequence of data, of no

particular length.

 Java classes can be categorised into two

groups based on the data type one which

they operate:

 Byte streams

 Character Streams

Streams

Byte Streams Character streams

Operated on 8 bit (

byte) data.

Operates on 16-bit

(2 byte) unicode

characters.

Input

streams/Output

streams

Readers/ Writers