Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code:
C#
FileInfo theSourceFile = new FileInfo(@"C:\WindowsFormsApplication1.txt");
StreamWriter str1 = new StreamWriter(@"C:\WindowsFormsApplication2.txt", false);
StreamReader stream = theSourceFile.OpenText();
string sline;
while ((sline = stream.ReadLine()) != null)
{
    string hex = "";
    foreach (char c in sline)
    {
        int tmp = c;
        hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
    }

    str1.WriteLine(hex);
    str1.Close();

}
stream.Close();

Infact I want to read from one file and convert data read and after it i write it in another file
is error is vshost.exe
Posted
Updated 10-Jul-12 4:51am
v3
Comments
[no name] 10-Jul-12 10:21am    
In this reposting of your question, do you have an actual question? If you had a question I would say that your question is something like, "Why does this only work once and then I get an error?" For which the answer would be, because you are writing the hex string the first time through and then closing the stream so the second time through, you would get an error.
Kschuler 10-Jul-12 10:23am    
What isn't working with that code? What errors are you getting? Can you please use the Improve Question link to add more details about your issue?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900