求解。。。将数字写入文件时变成对应的ASCII码了!请问怎么解决》?
求解!!! --------------------编程问答-------------------- 写入的时候传一个编码的参数 --------------------编程问答-------------------- 啊?什么意思》?我是从文本框中输入数字的 --------------------编程问答-------------------- 你把代码贴出来看看吧 --------------------编程问答----------------------------------------编程问答--------------------
string str = "7438297402384";
StreamWriter sw = new StreamWriter("D:\\123.txt", false, Encoding.ASCII);
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];
int ascii = (int)ch;
sw.WriteLine(ascii);
}
sw.Close();
楼上应该理解错了,楼主的意思写入文件的是ASCII吗,希望是正常的字符. --------------------编程问答-------------------- 类中的代码:
public int WriteOneRecord(long num)
{
try
{
if (file != null && bw != null)
{
file.Seek(num * SIZE, SeekOrigin.Begin);
bw = new BinaryWriter(file);
foreach (clsSuoYin csy in Arr)
{
bw.Write(csy.Name);
bw.Write(csy.Age);
}
bw.Close();
}
}
catch (Exception ex) { string buff = ex.Message; return 0; }
return 1;
}
窗体中的代码:
private void button1_Click(object sender, EventArgs e)
{
int age;
int.TryParse(textBox2.Text, out age);
asy.add(textBox1.Text, age);
}
private void button2_Click(object sender, EventArgs e)
{
int flag;
try
{
asy.Open(FILENAME);
recs = asy.GetRecordCount();
asy.Open(FILENAME);
flag=asy.WriteOneRecord(recs);
if (flag == 1) { MessageBox.Show("输入成功","无错误"); }
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
finally { asy.Close(); }
} --------------------编程问答-------------------- 借用一下4楼的代码:
--------------------编程问答-------------------- 抱歉!我的代码在4楼!
string str = "7438297402384";
StreamWriter sw = new StreamWriter("D:\\123.txt", true, Encoding.UTF8);
sw.WriteLine(str);
sw.Close();
补充:.NET技术 , C#