string pathout="f:\\11.txt"; StreamWriter sw= new StreamWriter(pathout ,true ); string[] time=new string[100]; for (int i = 0; i <= time.Length; i++) { sw.WriteLine(time[i] + " "); } sw.Close(); sw.Dispose(); 路径名不要弄错了
我的代码跟你的一样,但是11.txt文件里面还是没有写入,不知道是什么问题啊? StreamWriter sw = new StreamWriter(pathout, true); for (int i = 0; i < 24; i++) { sw.WriteLine(time[i] + " "); } Console.ReadKey();
time在那赋值的,你看下文件大小是否有改变?完整代码贴出来看看。
sw.WriteLine(time[i].tostring() + " ");
static void Main(string[] args) { string path = "f:/1.txt"; string pathout="f:/11.txt"; string[,] str = new string[24, 3]; int[] time = new int[24]; double[] p = new double[24]; double[] e = new double[24]; try { FileStream fs = new FileStream(path, FileMode.Open); using (StreamReader sr = new StreamReader(fs)) { string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", ""); string[] str2 = line.Split(' '); for (int m = 0; m <24; m++) for (int n = 0; n < 3; n++) { str[m, n] = str2[3 * m + n];
for (int j = 0; j < 3; j++) { for (int i = 0; i < 24; i++) { time[i] =Convert .ToUInt16 (str[i, 0]) ; p[i] =Convert .ToDouble (str[i, 1]) ; e[i] = Convert.ToDouble(str[i, 2]); } } } StreamWriter sw = new StreamWriter(pathout, true); for (int i = 0; i < 24; i++) { sw.WriteLine(time[i] + " "); } Console.ReadKey(); } } catch (Exception f) { Console.Write("出现错误!{0}", f.Message); Console.ReadKey(); } }
static void Main(string[] args) {string path = "f:/1.txt"; string pathout="f:/11.txt"; string[,] str = new string[24, 3]; int[] time = new int[24]; double[] p = new double[24]; double[] e = new double[24]; try { FileStream fs = new FileStream(path, FileMode.Open); using (StreamReader sr = new StreamReader(fs)) {string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", ""); string[] str2 = line.Split(' '); for (int m = 0; m <24; m++) for (int n = 0; n < 3; n++) { str[m, n] = str2[3 * m + n];for (int j = 0; j < 3; j++) { for (int i = 0; i < 24; i++) { time[i] =Convert .ToUInt16 (str[i, 0]) ; p[i] =Convert .ToDouble (str[i, 1]) ; e[i] = Convert.ToDouble(str[i, 2]); } } } StreamWriter sw = new StreamWriter(pathout, true); for (int i = 0; i < 24; i++) { sw.WriteLine(time[i] + " "); } sw.close(); Console.ReadKey(); } } catch (Exception f) { Console.Write("出现错误!{0}", f.Message); Console.ReadKey(); }}
string pathout="f:/11.txt";
……
StreamWriter sw= new StreamWriter(pathout ,true );
sw.WriteLine(time[i] + " ");
……
输出文件11.txt里面没有想要的time[]数组,请大虾们解救一下!
string[] time=new string[100];
for (int i = 0; i <= time.Length; i++)
{
sw.WriteLine(time[i] + " ");
}
sw.Close();
sw.Dispose();
路径名不要弄错了
StreamWriter sw = new StreamWriter(pathout, true);
for (int i = 0; i < 24; i++)
{
sw.WriteLine(time[i] + " ");
}
Console.ReadKey();
static void Main(string[] args)
{ string path = "f:/1.txt";
string pathout="f:/11.txt";
string[,] str = new string[24, 3];
int[] time = new int[24];
double[] p = new double[24];
double[] e = new double[24];
try
{
FileStream fs = new FileStream(path, FileMode.Open);
using (StreamReader sr = new StreamReader(fs))
{ string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", "");
string[] str2 = line.Split(' ');
for (int m = 0; m <24; m++)
for (int n = 0; n < 3; n++)
{
str[m, n] = str2[3 * m + n];
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 24; i++)
{
time[i] =Convert .ToUInt16 (str[i, 0]) ;
p[i] =Convert .ToDouble (str[i, 1]) ;
e[i] = Convert.ToDouble(str[i, 2]);
}
}
}
StreamWriter sw = new StreamWriter(pathout, true);
for (int i = 0; i < 24; i++)
{
sw.WriteLine(time[i] + " ");
}
Console.ReadKey();
}
}
catch (Exception f)
{
Console.Write("出现错误!{0}", f.Message);
Console.ReadKey();
} }
static void Main(string[] args)
{string path = "f:/1.txt";
string pathout="f:/11.txt";
string[,] str = new string[24, 3];
int[] time = new int[24];
double[] p = new double[24];
double[] e = new double[24];
try
{
FileStream fs = new FileStream(path, FileMode.Open);
using (StreamReader sr = new StreamReader(fs))
{string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", "");
string[] str2 = line.Split(' ');
for (int m = 0; m <24; m++)
for (int n = 0; n < 3; n++)
{
str[m, n] = str2[3 * m + n];for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 24; i++)
{
time[i] =Convert .ToUInt16 (str[i, 0]) ;
p[i] =Convert .ToDouble (str[i, 1]) ;
e[i] = Convert.ToDouble(str[i, 2]);
}
}
}
StreamWriter sw = new StreamWriter(pathout, true);
for (int i = 0; i < 24; i++)
{
sw.WriteLine(time[i] + " ");
}
sw.close();
Console.ReadKey();
}
}
catch (Exception f)
{
Console.Write("出现错误!{0}", f.Message);
Console.ReadKey();
}}
rw.WriteLine("");
rw.Flush();
rw.Close();
遍历数组