Doubt in java programming.
Hello friend's,
Check out this program.
Check out this program.
import java.io.*;What's wrong with this one..??
public class r
{
public static void main(String args[])throws IOException
{
try
{
FileReader fr=new FileReader("mohit.txt");
FileWriter fw=new FileWriter("monu.txt");
int s;
while((s=fr.read())!=-1)
{
fw.write(s);
}
}
catch(Exception e)
{
System.out.println("exception occured ");
}
}
}
Replies
-
Saandeep SreerambatlaYou have to use fw.close(); after the while loop.
-
Morningdot HabluYeh it's working.
.
Now i comes to the main problem what i faced.
Check out this program ES
import java.io.*;
This program will be written using byte stream in this program i didn't close the streams and it's working but in the case of character stream we must have to close the stream's.
public class r
{
public static void main(String args[])throws IOException
{
try
{
FileInputStream fr=new FileInputStream("mohit.txt");
FileOutputStream fw=new FileOutputStream("monu.txt");
int s,d;
s=fr.read();
fw.write(s);
}
catch(Exception e)
{
System.out.println("exception occured ");
}
}
}
Can you tell me the reason why..?? -
Saandeep SreerambatlaThis is the information I found from a friend!
In the FileReader operation the data is written onto Buffer it seems, and you can use flush() or close() for getting the file written! -
Morningdot HabluThanks ES !!
I got the answer. -
Saandeep Sreerambatla@Mohit:
Read this point , we need to close the file stream as well.
Always Close Streams ,Closing a stream when it's no longer needed is very important — so important that CopyBytes uses a finally block to guarantee that both streams will be closed even if an error occurs. This practice helps avoid serious resource leaks.
You are reading an archived discussion.
Related Posts
Hey ,
Post here how's your day????
And share your thoughts here.......
such that you can feel relax...........
write anything you want NO RESTRICTIONS WILL BE APPLIED HERE......
If angry...
HI Guys, I think the war between Amd and Intel is very long. Everyday many people meet who have different opinion about these processor manufacturer. Who use Intel they say...
Hi, guys I recently search details for i core processor made by Intel. I just got shocked when I know that core i3 and core i5 600 series processor are...
Hi,Guys. I have 3 hdd. On first I install windows 7 (main operating system), now on second hdd i install fedora 13. As i install Fedora 13 for learning and...
hello all,am currently in college studying to be an engineer,and am at the minute involved in a project on ocean energy,i am wondering if there is any entry level software...