files

files

1.Create a class called ReadFromFile. Create a file object and use the file object to create an input stream object to read the file â??employee.txtâ?? (use byte stream classes).If the file does not exists an exception should be thrown. An error message along with the path of the file(use the getAbsolutePath() method) should be displayed.

View Answers

March 9, 2011 at 12:41 PM

import java.io.*;
class InputStreamAndOutputStream 
{
    public static void main(String[] args)throws Exception{
     File f=new File("C:/Hello.txt");
     if(f.exists()){
     InputStream in = new FileInputStream(f);
     OutputStream out = System.out;
     int nextChar;
     while ( ( nextChar = in.read() ) != -1  )
     out.write((char) nextChar );
     out.write('\n' );
     out.flush();
     }
     else{
         System.out.println(f.getAbsolutePath()+" does not exist");
     }
    }
}









Related Tutorials/Questions & Answers:
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code:ADS_TO_REPLACE_1 import java.io.*; import
Advertisements
Files
files
files
files
files
files
header files
header files   do you have a all header files of java
Uploading files
Uploading files  Hi, Please provide html code for my question. I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
configuration files are used in Struts
configuration files are used in Struts  What configuration files are used in Struts
files uploding and downloading codes
files uploding and downloading codes  any one know JSP codes for upload files,download files and delete files from a created virtual memory
invoking exe files on sound
invoking exe files on sound  how to invoke .exe files on input as sound in java
ModuleNotFoundError: No module named 'files'
ModuleNotFoundError: No module named 'files'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'files' How to remove the ModuleNotFoundError: No module named 'files'
download pdf files
download pdf files  pls help me,I don't know how to convert .doc,.docx files into pdf files and download that pdf files using servlet or jsp
php merge files
php merge files  Split and merge files in PHP Classes
replacing regex in large files
replacing regex in large files  replacing regex in large files
get files list - Ajax
get files list  Please,friend how to get files list with directories from ftp server or local files on web browser. Thanks, Tin Linn Soe   Hi friend, Index of Files Index
Retrieving list of uploaded files.
Retrieving list of uploaded files.  I need to retrieve list of files... files on a website. its uploaded. now the file resides in a directory in the server. now the list of uploaded files should be showing in page where other users can
files - Java Beginners
files  Why do we require files to store data?  Hi friend, files to store data, easy to find and access them. Thanks
library files - Development process
library files   Hi members, i am trying to develop a media player in java using netbeans but what library files should i import for this development
merge two war files
merge two war files  How to merge two war files using maven??? is there any command
merge two war files
merge two war files  how to merge two war files using maven
php show list of files
php show list of files  How can i pull the limited number of files in PHP
intersection of two files
intersection of two files  hi!could you please provide me with the java program for displaying intersection of two files
Structs jar files
Structs jar files  please Post required jar files for structs. Thanks, L.Mahesh Kumar
compiling .class files
compiling .class files  how do i compile .class files using eclipse
List files recursively in linux
List files recursively in linux  Hi, How to List files recursively in linux? I want to list all the .php file. Thanks   Hi, You can use following command: find . -name *.php -print Thanks
getting files from VSS
getting files from VSS  I am not able to get the files from VSS.I am using following code. and just let me know is localpath attribute is for our local project path? I am getting the problem in this line failed
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit the form.Send em the answers as soon as possible..   Please visit
encryption and decryption of files
encryption and decryption of files   Please can any one provide me with the code for encryption and decryption of files using RSA algorithm. I want to use a browse option to search for the file which is needed for encryption
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Reading multiple xml files
Reading multiple xml files  How can we read many xml files from a folder? The same procedure as that of "listfiles
Renaming multiple files
Renaming multiple files  Hi, I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. .... Now I wanted to rename these files as: 1RohitBBorse.mp4
Tomcat access to network files
Tomcat access to network files  i have web application which is running on tomcat 6.0, it access network files from JSP. but i am getting an errror. please help
Resource files in iphone
Resource files in iphone  hiii how can we use resource files in iphone development ???   hello, ADS_TO_REPLACE_1 if you want to use any file in your application the first you have to added it in your resource folder
Compare 2 files
Compare 2 files  I would like to compare 2 files in Java. please send me the code snipt for this scenario: File1... to compare these files and print the diffrence by comparing the report name
Reading files in Java
Reading files in Java  I have to make a program in my project of finance that reads the text file and process the data in it. How to read the text... suggest for Reading files in Java? Thanks
configuration files - Java Beginners
configuration files  i have to use configuration file in my program "listing of number of files and their modified time of directory",but problem is that directory name should be provided through configuratin file not input
Developer Files - Development process
Developer Files  Hi, I dont have real time experience. can u tell as a j2ee developer should i edit struts properties files or not . like wise changes in any other properties file. Thanks Prakash
quqtion on jar files
quqtion on jar files  give me realtime examples on .jar class files   A Jar file combines several classes into a single archive file. Basically,library classes are stored in the jar file. For more information,please go
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... a list of JPEG files that my boss gave me, and I was planning on putting them
listing files - Java Beginners
listing files  how to list the files and number of files only...]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow
regarding header files - Spring
*; As per tutorail i have copied spring.jar and commaon-logging .jar files in cureent
Creating files of PDF's thumnails
Creating files of PDF's thumnails  Hi, How to create PDF's thumbnail in PHP? Thanks   Hi, You should have ImageMagick support on your server. You can then use following code to create PDF thumbnail image. <?php
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
How to list files in hadoop?
How to list files in hadoop?  Hi, I want to list the files from a directory in HDFS. How to list files in hadoop? Thanks   Hi, Hadoop... the files from the root of HDFS. Sample output: hdfs@hadoop1:/home/deepak
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI... show the particular txt files of the selected date. I want the java logic... in the database for files. import java.awt.*; import java.sql.*; import java.util.
storing data into flat files
storing data into flat files  how can i retrive data from database and store data in flat files   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.io.*; import java.sql.*; import java.util.*; class

Ads