|
-
Mar 15th, 2008, 06:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Streamwriter does NOT write complete file
Hello Friends,
I have a code which reads a text file through streamreader,
selects what is important and writes the same to another file
using streamwriter. The problem is that the streamwriter stops
writing beyond a certain line and just doesnt write ahead.
What can be the problem? Do I have to make two seperate files?
Regards,
Sid.
THE BEST WAY TO THANK A HELPFUL POST IS TO RATE IT!!!!
Take up one idea. Make that one idea your life - think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone.
-
Mar 15th, 2008, 06:54 AM
#2
Re: Streamwriter does NOT write complete file
Rather than forcing us to guess what is wrong with the code, how about showing it, that might be a good start...
-
Mar 15th, 2008, 07:35 AM
#3
Thread Starter
Addicted Member
Re: Streamwriter does NOT write complete file
Ok, its something like this............
Code:
dim tempstr as string
dim d as new directoryinfo("c:\temp", "*.txt")
dim files() as string = d.getfiles()
dim count as integer = files.getlength(0) 'thats the first dimension
dim start as integer
dim str as new streamwriter("C:\logfile.txt")
for start = 0 to count
dim f as new filestream(files(start), createmode, writemode)
dim s as new streamreader(f)
do
tempstr = s.readline()
str.writeline(tempstr)
While Not s Is Nothing
*****************************************************
Now when I check out the "logfile.txt"written it is incomplete. Only about
75% of the file is written. Also there are too many text files in the C:\temp
folder(about 3 GB)...What might be the reason?
THE BEST WAY TO THANK A HELPFUL POST IS TO RATE IT!!!!
Take up one idea. Make that one idea your life - think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone.
-
Mar 15th, 2008, 07:57 AM
#4
Re: Streamwriter does NOT write complete file
you're looping until s is nothing. S will not become 'Nothing' just because it reaches the end of the line. Loop until s.EndOfStream instead.
-
Mar 15th, 2008, 09:32 AM
#5
Thread Starter
Addicted Member
-
Mar 15th, 2008, 09:38 AM
#6
Thread Starter
Addicted Member
-
Mar 15th, 2008, 09:44 AM
#7
Thread Starter
Addicted Member
-
Mar 15th, 2008, 12:12 PM
#8
Re: Streamwriter does NOT write complete file
Try something like this:
Code:
Dim file1path As String = "path to file1 here"
Dim file2path As String = "path to file2 here"
Dim reader As New IO.StreamReader(file1path)
Dim writer As New StreamWriter(file2path)
While reader.Peek <> -1
writer.WriteLine(reader.ReadLine())
End While
reader.Close()
writer.Close()
-
Mar 17th, 2008, 06:56 AM
#9
Thread Starter
Addicted Member
-
Jun 21st, 2012, 01:27 PM
#10
New Member
Re: [RESOLVED] Streamwriter does NOT write complete file
I was having the same problem and this solved it. Thank you!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|