FileStream fs;
BinaryReader br;
BinaryWriter bw;
string s = "";
public Login()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
char[] user = { 'j','i','n','g','l','i','x','i','t','o','n','g'};
cmbjob.SelectedIndex = 0;
fs = new FileStream(@"C:\Program Files\login.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite,FileShare.Read);
br = new BinaryReader(fs);
bw = new BinaryWriter(fs);
for (int i = 0; i < user.Length; i++)
{
bw.Write((int)user[i]+5);
}
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (cmbjob.Text == "经理")
{
br.BaseStream.Seek(0, SeekOrigin.Begin);
while (br.PeekChar()> -1)
{
s += br.BaseStream
}
MessageBox.Show(s);
}
else
{
}
}大概的代码是这样的,数组里的每个字符转换成ASCII码,起到加密的作用,文件里面的内容是:
o n s l q n } n y t s l
可是我想把这些读出来的时候却读不出来,麻烦大家看一下要用什么方法才能读出来?谢谢
/// 读取Txt文件
/// </summary>
/// <returns></returns>
public static ArrayList GetFiles(string FileName)
{
#region 数据读取
try
{
FileStream fs = new FileStream(Application.StartupPath + FileName, FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs, Encoding.GetEncoding("GB2312"));
//使用StreamReader类来读取文件
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
// 从数据流中读取每一行,直到文件的最后一行
string strLine = m_streamReader.ReadLine();
ArrayList arraylist = new ArrayList();
while (strLine != null)
{
arraylist.Add(strLine);
strLine = m_streamReader.ReadLine();
}
//关闭此StreamReader对象
m_streamReader.Close();
if (arraylist.Count > 0)
{
return arraylist;
}
else
{
return null;
}
}
catch(Exception)
{
MessageBox.Show("数据读取失败,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}