Results 1 to 5 of 5

Thread: Writing to a file

  1. #1
    dmartin17
    Guest

    Writing to a file

    Can someone please help me figure out how to write to a file. I am using the binarywriter right now but this is giving me weird out put. take a look at the sample code below:

    string outputFile = "csharp.htm";
    string path = "c:/";
    FileStream output;
    output = new FileStream( path + outputFile, FileMode.OpenOrCreate, FileAccess.Write);
    BinaryWriter binaryOutput = new BinaryWriter(output);
    binaryOutput.Write("<html>\n<head>\n<title>C#!</title>\n</head><body>\n");

    Thats jsuta tid bit there is actually more code ot it but that is the essentials. This gie me weird output with either one of those block characters or a random slash or somethign else at the beginning of every .Write("something") i do.

    can anyone help?

  2. #2

  3. #3
    seljuk
    Guest

    Use streamwriter

    FileStream f=new FileStream("filename".FileMode.OpenOrCreate);
    StreamWriter sw=new StreamWriter(f);
    sw.write("your text here...........");

  4. #4
    dmartin17
    Guest
    MOHH---

    did you try this
    Code:
    File.Exists("filename.dat");
    That might work. I'm not sure if it checks the working directory but i'd assume so. Try that though

    btw- when switching subjects like this its best to start a new thread.

  5. #5
    dmartin17
    Guest
    Code:
    StreamReader stream = new StreamReader(path + filename);
    FileStream output = new FileStream( path + outputFile, FileMode.OpenOrCreate, FileAccess.Write);
    StreamWriter sw = new StreamWriter(output);
    this is how i did my input and output from file.

    path, filename, outputFilename are all string variables containing file info to use for input and output

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width