Results 1 to 3 of 3
Thread: File Writting problem??????
- 01-06-2012, 09:08 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 27
- Rep Power
- 0
File Writting problem??????
Code is::::
public static void getFile(String s) throws IOException
{
File f=new File(s);
boolean b=f.exists();
if(b)
{
System.out.println("File Exist ");
try
{
FileInputStream fstream = new FileInputStream(s);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
FileWriter fostream = new FileWriter("d:/report.txt");
//file is created on d:/report.txt
BufferedWriter out = new BufferedWriter(fostream);
while ((strLine = br.readLine()) != null) {
String line_allow="HELLO";
out.write(line_allow);
//but string is not written in file report.txt
}
}
catch(Exception e)
{
}
}
else
System.out.println("File Not Exist ");
}
Problem is the file report.txt does not contain anything?
blank file !!!
what is the problem in code???
help?????
- 01-06-2012, 10:12 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: File Writting problem??????
First use code tags, otherwise the code is hard to read.
Next, never eat exceptions...always at the least do e.printStackTrace(), otherwsie you'll never know when something has gone wrong.
Also, your use of streams and readers is seriously confused. That DataInputStream is completely unecessary. It should be simply:
Also (and I suspect this could be your real problem) you don't seem to ever close the streams (which should be done in a finally block as part of the try/catch)?Java Code:BufferedReader br = new BufferedReader(new FileReader(f));
- 01-07-2012, 02:49 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 15
- Rep Power
- 0
Re: File Writting problem??????
Perhaps this tutorial will come in handy:
Dystopian Code: Text File I/O in Java
Similar Threads
-
txt reading and writting
By zenitis in forum New To JavaReplies: 0Last Post: 05-09-2011, 12:27 AM -
java file writting
By karq in forum New To JavaReplies: 3Last Post: 07-07-2010, 08:38 PM -
Problem with writting in JEditorPane.
By marox in forum AWT / SwingReplies: 11Last Post: 04-20-2010, 11:25 PM -
Writting output to file!
By hakan123 in forum New To JavaReplies: 8Last Post: 11-19-2009, 04:39 PM -
writting extended ascii chars on socket........or Endianness Issue......??
By sachinj13 in forum Threads and SynchronizationReplies: 8Last Post: 09-23-2008, 02:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks