FILE HANDLING CONCEPT

FILE HANDLING CONCEPT

Write a program to read and write the details of an employee like year of joining, Department code, salary using some byte stream classes.

View Answers

June 15, 2012 at 4:31 PM

The given code accepts the details from the user like year of joining, Department code, salary, employee name etc.This data is then stored into the text file using ByteArrayOutputStream class.

import java.io.*;

class  RandomAccessFileExample{
    public static void main(String[] args){
        try{
            File f=new File("c:/employee.txt");
            ByteArrayOutputStream arr=new ByteArrayOutputStream();


            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter year of joining: ");
            int year=Integer.parseInt(br.readLine());

            System.out.print("Enter department code: ");
            String dcode=br.readLine();

            System.out.print("Employee Name: ");
            String name=br.readLine();

            System.out.print("Salary: ");
            long sal=Long.parseLong(br.readLine());

            String str=Integer.toString(year)+" "+dcode+" "+name+" "+Long.toString(sal);
            byte buf[] = str.getBytes();
            arr.write(buf); 
            OutputStream f2 = new FileOutputStream(f);
            arr.writeTo(f2);
            arr.close(); 
            f2.close(); 

        }
        catch(Exception e){}
    }
}









Related Tutorials/Questions & Answers:
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
Advertisements
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Write a program to read and write the details of an employee like year of joining, Department code, salary using some byte stream classes
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does
FILE CONCEPT
FILE CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does not exist print
File Handling
File Handling  how we do file handling of parsed XML code bu DOM in java
File handling
File handling  how do i search for an occurance of a word in a file... in a file import java.io.*; import java.util.*; class FileOperations{ public static void main(String[] args)throws Exception{ int count=0; File f
File handling in Java
File handling in Java  Hi, Can any one tell me the basics of File handling in Java? ThanksADS_TO_REPLACE_1   Hi, File handling... provide very good file handling features in their api.ADS_TO_REPLACE_2 You can read
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  In a random access file, first write the alphabets a,b, c, d till z. Read the file in reverse order and print it on screen
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program that stores the names of four employees in an array of strings. Store the contents of the array in an alphabetical order in a file and display it back on console. Do not use
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to use a File object and print even numbers from two to ten. Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print only the last 3 digits
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to write the details of an employee to a file. Details such as year of joining, department code, employee name and salary should be included. You must use RandomAccessFile
File Handling in Java
File Handling in Java  Hi, While opening a file in Java developers... was trying to find some tutorials about handling file in Java on net. I have also seen... are the use of these classes? Is there example code for explaining the File Handling
Excel file Handling in Java
Excel file Handling in Java  Hello Sir, I am new to Java, I have Started Java Core by myself. I want to make a project which include 3-4 Excel file to handle.Please explain how to read and write Excel file in Java.Is it tough
java file handling
java file handling  enter string from keyboard and then read a file if this string is present in file then print message already exists else write this string to file
java file handling
java file handling  program to get values from textbox array and the write them to text files
File Handling - Java Beginners
File Handling  Thanks for replying me.. but i am sorry to say...; System.out.print("Enter the file name : "); name = br.readLine(); name = "d...{ File f; f= new File(name); if(f.exists()){ RandomAccessFile rand
java file handling
java file handling  Hi friends, My situation is i have file named "sample.conf" which contains more IP Adressess.Eg: the file contains "IP=255.255.255.255" at some lines in the file. what i need to do is. i need to search
File Handling - Java Beginners
File Handling  I have written one program by which we can create a file , store any information in that,and resume that file using a user name and password.now my problem is that whenever i write datas into the file the previous
file handling - Java Beginners
file handling  assume two files are there- 1. with the quanity of he... manner. now write a progam in java and create another file which is having the amount required to purchase each item and at last read the newly created file
File Handling - Java Beginners
File Handling  Q. Write a java prg which accepts a list of existing text files from command line args & concatinate contents of all files...(e.getMessage()); } } }   its prg of copying file Check code
File Handling In Java
File Handling in Java In this section we will discuss about the file handling in Java. This section describes you about how to perform file handling in Java. In this section you will read what is file handling in Java, how to perform
Java File Handling Test Results
Java File Handling Test Results   Is somebody able to help me with this Write a program to read each name from the file and prompt the user... FileNotFoundException { new File("team.html").delete(); Scanner scan = new
exception handling code for file not found error..
exception handling code for file not found error..  How to do exception handling for file not found error
File Handling Classes in Java
In this section, you will get to know about file handling classes in java to handle the file input output operations
PHP File Handling
PHP File Handling: Every language supports File handling, file handling has... file handling. PHP supports this feature using the following functions: i)    fopen: To open a file in a particular mode, like r: read, w
Java File Handling
File Handling in Java       File Handling in Java For file handling... of this super class. FileInputStream In a file system, it gets input
exception handling
exception handling  could you please tell me detail the concept of exception handling
Java file not found exception
Java file not found exception This section illustrates you the concept of file not found exception. Java provides a powerful concept of Exceptions... the concept of file not found exception. Output
Java file exception
Java file exception This section illustrates you the concept of file exception... to understand the concept of file exception. Output:ADS_TO_REPLACE_2... or it is generated by a code.  In the given example, we have specified a file
Java file object
Java file object This section demonstrates you the concept of File object... the programming much easier. Here we will discus the operations performed by File object. Using the File object, you can perform several operations. It parses
exception handling
exception handling  explain about exception handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
Explain normalization concept?
Explain normalization concept?  Explain normalization concept
event handling
event handling  diff btwn event handling in ASP.net and in HTML
IO concept
file to another and deletes the old file.   Hi Friend, Try...[] args) throws Exception { File f1=new File("C:/data.txt"); File f2=new File("D:/data.txt"); BufferedReader br=new BufferedReader(new
unicode handling in java
unicode handling in java  reading a unicode text file in java
File Handling
exception handling
exception handling   Give the exception hierarchy of Java.   Please visit the following links: http://www.roseindia.net/java/java-exception/exception-java.shtml http://www.roseindia.net/java/exceptions/exception
exception handling
exception handling  What is an exception and what are the advantages of exception handling mechanism.   Java Exception Exception... the working code and the error-handling code can be disintegrated. It also gives us
Concept of subqueires using JSP
Concept of subqueires using JSP  Can I implement the concept of sub queries in JSP page , if yes please tell me how this can be achieved. I have requirement where output of the SQL query should be given as input to the update

Ads