|
-
Apr 11th, 2002, 03:18 PM
#1
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?
-
Apr 11th, 2002, 03:40 PM
#2
Hyperactive Member
-
Apr 17th, 2002, 05:33 PM
#3
Use streamwriter
FileStream f=new FileStream("filename".FileMode.OpenOrCreate);
StreamWriter sw=new StreamWriter(f);
sw.write("your text here...........");
-
Apr 17th, 2002, 06:45 PM
#4
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.
-
Apr 17th, 2002, 06:50 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|