New Member FAQ
|
Forums
|
Earn Revenue
Resources
Entrance
Ask Experts
Exam Papers
Jobs
English
Projects
Universities
Colleges
Courses
Schools
Training
My India
Members
|
Communities
|
Business Directory
|
Classifieds
|
Reviews
|
Silverlight Games
|
Peer Appraisal
|
Bookmarks
|
Polls
|
Mentors
|
Links
|
MCA Projects
|
Lobby
|
Gift Shop
|
Chat
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
PROSENJIT MANN...
(667)
Mr. Anindya
(477)
Lenin
(364)
Last 7 Days
PROSENJIT MANN...
(1781)
Shobha Manasa
(1774)
Lenin
(1522)
more...
Awards & Gifts
Online Exams
Aptitude Questions
General Aptitude Tests
Medical Entrance
Engineering Entrance
Bank Tests
TOEFL & IELTS Questions
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Writing into file - Java
Posted Date: Total Responses:
0
Posted By:
Annapurna
Member Level:
Gold
Points/Cash
: 3
import java.io.*;
public class WriteIntoFile
{
public static void main(String[] args)
{
FileOutputStream fos = null;
File file = new File ("File1.txt");
try
{
if (! file.exists() )
{
file.createNewFile();
System.out.println("New File is Created. ");
}
else
System.out.println("File already exists.");
fos = new FileOutputStream(file, true);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the text you want to enter into file");
System.out.println("Enter @ at the end");
String str = null;
while(true)
{
str = br.readLine();
String s = " ";
str = str + s;
if((str.charAt(str.length() - 2)) == '@')
{
str = str.substring(0, str.length() - 2);
// System.out.println(str);
fos.write(str.getBytes());
System.out.println("Successfully added.");
break;
}
fos.write(str.getBytes());
}
fos.close();
FileReader fr = new FileReader(file);
LineNumberReader ln = new LineNumberReader(fr);
int count = 0;
while (ln.readLine() != null){
count++;
}
System.out.println("No. of lines are : " +count);
System.out.println("Absolute path of the file is : " +file.getAbsolutePath());
}
catch(FileNotFoundException f)
{
System.out.println(f);
}
catch(IOException ie)
{
System.out.println(ie);
}
finally
{
System.out.println("The Size of the file is : " +file.length());
}
}
}
Project Feedbacks
No feedbacks found. Be the first to respond and make money from
revenue sharing program
.
Post Feedback
You must
Sign In
to post a feedback.
Next Project:
Retrieving employee details by giving employee id - Java
Previous Project:
Example program for Null Pointer Exception - Java
Return to Project Index
Post New Project
Related Projects
Operations on Binary Search Tree
Operations on Linked List
Project on calculator ( using C language )
Tic TacToe Game
Assembly Chain Scheduling in C++
Advertise Here
Contact Us
Advertise
Editors
Privacy Policy
Terms Of Use
ISC Technologies.
2006 - 2009 All Rights Reserved.