现在有一个1.txt文件,内容是一个1,用二进制的方式把他读到另外一个文件2.txt中是49,不知道为什么是49(这个不重要),然后读2.txt文件,要读到的内容是1,怎么样读呢。读到的变量data是49,求救啊!!!!!!!!!!!
string pathbody = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\1.txt";
string pathheader = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\2.txt";
byte[] arrFile=null;
using (FileStream fs2 = new FileStream(pathbody, FileMode.Open))
{
arrFile= new byte[1];
fs2.Read(arrFile, 0, 1);//读1.txt的文件
using (StreamReader sr = new StreamReader(fs2))
{
using (StreamWriter sw1 = new StreamWriter(pathheader, true))
{
for (int i = 0; i < 1; i++)
{
sw1.Write(arrFile[i]); }
}
} } using (FileStream fsBody = new FileStream(pathheader, FileMode.Open, FileAccess.Read))
{ using (StreamReader sw1 = new StreamReader(fsBody))
{
string str = sw1.ReadLine();
byte[] demo = System.Text.Encoding.Default.GetBytes(str);
string data = System.Text.Encoding.Default.GetString(demo);
}
}
string pathbody = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\1.txt";
string pathheader = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\2.txt";
byte[] arrFile=null;
using (FileStream fs2 = new FileStream(pathbody, FileMode.Open))
{
arrFile= new byte[1];
fs2.Read(arrFile, 0, 1);//读1.txt的文件
using (StreamReader sr = new StreamReader(fs2))
{
using (StreamWriter sw1 = new StreamWriter(pathheader, true))
{
for (int i = 0; i < 1; i++)
{
sw1.Write(arrFile[i]); }
}
} } using (FileStream fsBody = new FileStream(pathheader, FileMode.Open, FileAccess.Read))
{ using (StreamReader sw1 = new StreamReader(fsBody))
{
string str = sw1.ReadLine();
byte[] demo = System.Text.Encoding.Default.GetBytes(str);
string data = System.Text.Encoding.Default.GetString(demo);
}
}
解决方案 »
- 正则怎么写?
- winfrom Tabcontrol美化后不能使用DrawItem 事件
- C#清除一个事件的所有委托
- C# 如何在子窗体中更改主窗体的属性.
- C#如何动态操作xml节点属性
- 项目合作
- [竹子]问个GDI+问题:Graphics.DrawString()有显明锯齿, 怎么解决?
- .net winform 程序中,程序连接远程sql数据库,默认端口是1433,想换个端口连接,需要在程序连接数据库字符串和远程sql数据库怎么操作才
- CPU占用率100%的解决办法???
- Ribbon for WPF 微软官方示例,标题栏怎么这副鸟样啊
- Repeater绑定数据用到两个表的内容
- 为什么我用socket连接,只能发送/接收一次数据,然后监听就自动关闭了?能不能无限监听
------------------------ if (File.Exists("路径/XX.txt"))
{
if (!this.txtAA.AutoCompleteCustomSource.Contains(txtAA.Text))//判断记录是否存在
{
StreamWriter sw = new StreamWriter("路径/XX.txt", false);//true参数不可少,否则会覆盖以前存入的记录
sw.WriteLine(this.txtAA.Text.Trim());//存入记录
sw.Close();
if (!this.txtAA.AutoCompleteCustomSource.Contains(this.txtAA.Text))
{
this.txtAA.AutoCompleteCustomSource.Add(this.txtAA.Text);
}
}
this.DialogResult = DialogResult.OK;
}
--------- if (File.Exists(@"../../XX.txt"))//路径和文件类型大家自己设置
{
StreamReader sr = new StreamReader(@"../../XX.txt", true); string str = sr.ReadLine();
if (str != null)
{
txtAA.Text = str.Trim();
}
sr.Close();
}
string pathheader = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\2.txt";
byte[] arrFile=null;
using (FileStream fs2 = new FileStream(pathbody, FileMode.Open))
{
arrFile= new byte[1];
fs2.Read(arrFile, 0, 1);//读1.txt的文件
string sData = System.Text.Encoding.Default.GetString(arrFile);
using (StreamReader sr = new StreamReader(fs2))
{
using (StreamWriter sw1 = new StreamWriter(pathheader, true))
{
for (int i = 0; i < 1; i++)
{
sw1.Write(sData ); }
}
} } using (FileStream fsBody = new FileStream(pathheader, FileMode.Open, FileAccess.Read))
{ using (StreamReader sw1 = new StreamReader(fsBody))
{
string str = sw1.ReadLine();
byte[] demo = System.Text.Encoding.Default.GetBytes(str);
string data = System.Text.Encoding.Default.GetString(demo);
}
}
我是想把1.txt内容存到2.txt文件的是二进制.你这样写存的是一样的内容。
看看去
</a>
4楼正解,1的ASCII正是49,转换一下就行了,他已经在下面给出解决办法了!