using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;using System.IO;namespace WindowsFormsApplication3{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string conn = "Data Source=(local); Database=modelsearch3;Integrated Security=SSPI;"; SqlConnection objcon = new SqlConnection(conn); SqlDataAdapter adapter; adapter = new SqlDataAdapter("select * from model", objcon); SqlCommandBuilder sqlBuilder = new SqlCommandBuilder(adapter); objcon.Open(); DataTable dt = new DataTable("model"); adapter.Fill(dt); for (int i = 0; i < 631; i++) { DataRow row = dt.Rows[i]; string f = row.ItemArray[4].ToString(); string s = row.ItemArray[7].ToString(); string t = row.ItemArray[8].ToString(); //StreamWriter fw = File.AppendText("C:\\frontString.txt"); //fw.Write(f + "\r\n"); //StreamWriter sw = File.AppendText("C:\\sideString.txt"); //sw.Write(s + "\r\n"); //StreamWriter tw = File.AppendText("C:\\topString.txt"); //tw.Write(t + "\r\n"); StreamWriter zw = File.AppendText("C:\\modelString.txt"); zw.Write(f + s + t + "\r\n"); //fw.Close(); //sw.Close(); //tw.Close(); zw.Close(); } } }}
参考:
http://zhidao.baidu.com/question/318486288.html
C#读取文本
int file_count = 0; StreamReader front_file_reader = new StreamReader("C:\\front_coordinate_add.txt"); StreamReader side_file_reader = new StreamReader("C:\\side_coordinate_add.txt"); StreamReader top_file_reader = new StreamReader("C:\\top_coordinate_add.txt"); ArrayList frontFeature = new ArrayList(); //前台sketch的特征符 (front) ArrayList sideFeature = new ArrayList(); //前台sketch的特征符 (side) ArrayList topFeature = new ArrayList(); //前台sketch的特征符 (top) while (file_count < 5) { string front_file_route = ""; front_file_route = front_file_reader.ReadLine(); string side_file_route = ""; side_file_route = side_file_reader.ReadLine(); string top_file_route = ""; top_file_route = top_file_reader.ReadLine(); string front_coordinate_str = ""; //char[] front_buffer = new char[30000]; StreamReader front_reader = new StreamReader(front_file_route); //front_reader.Read(front_buffer,0,29999); front_coordinate_str = front_reader.ReadLine(); //string front_coordinate_str = new string(front_buffer); front_reader.Close(); string side_coordinate_str = ""; StreamReader side_reader = new StreamReader(side_file_route); side_coordinate_str = side_reader.ReadLine(); side_reader.Close(); string top_coordinate_str = ""; StreamReader top_reader = new StreamReader(top_file_route); top_coordinate_str = top_reader.ReadLine(); top_reader.Close(); bool result = WordStreamMatching.getInstance().matching(front_coordinate_str, side_coordinate_str, top_coordinate_str, ref frontFeature, ref sideFeature, ref topFeature); if (!result) MessageBox.Show("123"); file_count++; }