C#PC上的程序如何访问WinCE上的txt文件!急!急!

昵称是啥玩意儿 2012-10-29 09:53:20
RT 搞了半天了!在PC机上有一个程序需要调用WinCE中的TXT文件!
...全文
204 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
XBodhi. 2012-10-29
  • 打赏
  • 举报
回复
直接 读取就可以了 ,用 FileStream
你要不就自己写一个 ,要不就自己装一个第三方,稍等我给你个代码。


using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace TextEditor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnOpen_Click(object sender, EventArgs e)
{
this.openFileDialog1.FileName = "TxtFile.txt";
this.openFileDialog1.Filter = "文本文件(*.txt)|*.txt|All Files(*.*)|(*.*)";
this.openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
DialogResult dlg = this.openFileDialog1.ShowDialog();
if (dlg == DialogResult.OK)
{
txtFilePath.Text = this.openFileDialog1.FileName;
FileInfo file = new FileInfo(txtFilePath.Text.Trim());
using (StreamReader sreader = new StreamReader(file.OpenRead()))
{
txtContant.Text = sreader.ReadToEnd();
}
}
}

private void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtFilePath.Text.Trim()))
return;
using (FileStream fs = new FileStream(txtFilePath.Text.Trim(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(txtContant.Text.Trim());
}
}
MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}

private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
  • 打赏
  • 举报
回复
在线等~

17,748

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧