问题描述
Stream如何保存成为文件?通过webRequest获得流,但是不知道如何保存为物理文件啊!
解决方案
解决方案二:
up
解决方案三:
例子:privatevoidbtncsv_ButtonClick(objectsender,EventArgse){if(dataGridView1.Rows.Count<=0){return;}saveFileDialog1.Title="CSV出力";saveFileDialog1.DefaultExt=".csv";//saveFileDialog1.InitialDirectory=@"c:";saveFileDialog1.RestoreDirectory=false;saveFileDialog1.FileName="";saveFileDialog1.FileOk+=newCancelEventHandler(this.saveFileDialog1_FileOk);saveFileDialog1.Filter="CSVファイル(*.CSV)|*.CSV|所有文件(*.*)|*.*";saveFileDialog1.ShowDialog(this);}#regionsaveFileDialog_fileokprivatevoidsaveFileDialog1_FileOk(objectsender,CancelEventArgse){stringpath=saveFileDialog1.FileName;try{if(path!=""){StreamWriterstrmCsv=newStreamWriter(path,true,System.Text.Encoding.GetEncoding("shift-jis"));strmCsv.WriteLine("ID,銀行区分,銀行コード,銀行名(漢字),(カナ),支店コード,支店名(漢字),(カナ),口座種別,口座番号,口座名義人(漢字),(カナ),出力フォーマット,表示順");for(inti=0;i<dtdata.Rows.Count;i++){stringdisplayData=dtdata.Rows[i]["sysbankinfo_id"]+","+dtdata.Rows[i]["banktype"]+","+dtdata.Rows[i]["bankcode"]+","+dtdata.Rows[i]["bankcname"]+","+dtdata.Rows[i]["bankaname"]+","+dtdata.Rows[i]["cbankcode"]+","+dtdata.Rows[i]["cbankcname"]+","+dtdata.Rows[i]["cbankaname"]+","+dtdata.Rows[i]["accounttype"]+","+dtdata.Rows[i]["accountno"]+","+dtdata.Rows[i]["accountcname"]+","+dtdata.Rows[i]["accountaname"]+","+dtdata.Rows[i]["outtype"]+","+dtdata.Rows[i]["orderby"];strmCsv.WriteLine(displayData);}strmCsv.Close();}}catch(IOExceptionev){MessageBox.Show(this,ev.Message);return;}finally{saveFileDialog1.FileName="";path="";}}
解决方案四:
是Stream并非StreamWriter
解决方案五:
StreamWriter接受Stream参数,接着你就可以用
解决方案六:
不对,请注意我的是stream并非是字符串,
解决方案七:
上面的没错,streamWriter/StreamReader是接受流对象做为参数的应该是用streamReader(Stream)读出来,再写入.
解决方案八:
StreamReaderreader=newStreamReader("00.txt");FileStreamfs=newFileStream("22.txt",FileMode.OpenOrCreate,FileAccess.Write);StreamWriterwriter=newStreamWriter(fs);