在C#中开发智能设备应用程序(PDA),在处理文件的读取时,我的应用程序部署到PDA上不能读取文件,而把此应用程序在WINDOWS里运行就可以.
疑问:PDA上是不是不能用OpenText这种方法打开文件?
程序代码如下:StreamReader s = File.OpenText("PD.ADB");
string read = null;
while ((read = s.ReadLine()) != null)
{
if (read.Substring(read.Length-2,1)!="0")
{
listBox1.Items.Add(read);
}
}
s.Close();
请各位朋友看看..帮下忙解决一下!
疑问:PDA上是不是不能用OpenText这种方法打开文件?
程序代码如下:StreamReader s = File.OpenText("PD.ADB");
string read = null;
while ((read = s.ReadLine()) != null)
{
if (read.Substring(read.Length-2,1)!="0")
{
listBox1.Items.Add(read);
}
}
s.Close();
请各位朋友看看..帮下忙解决一下!
解决方案 »
- toolStripButton按钮能不能不用图标,能不能像普通按钮那样写字?
- 让页面不能被复制
- 怎么样控制选择列表框里的值呢???
- 最后的分数了,全给了,望大家帮忙
- 一个小问题。
- 帮看一下,下面的代码执行后,不能写入数据库.
- 请问C#如何打包C的动态库?
- ?C#中DataGrid的分页问题
- Asp.net网页中水晶报表1
- 请给一段创建FTP Session的简明代码,包括应用哪些名称空间?并作解释。
- 如果实现DropDownList控件按照条件(条件为true就弹出,false就不弹)弹出确认(confirm)对话框???????????????
- Explorer.exe的cpu总是100%?
try
{
FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read);
myFuns.memset(sLine,myFuns.nDataRowLength,0); while (fs.Read(sLine,0,myFuns.nDataRowLength) > 0)
{
string s = System.Text.Encoding.Default.GetString(sLine,0,myFuns.nDataRowLength);
if (KeyCompare(s,sSearch))
{
fs.Close();
return s;
}
myFuns.memset(sLine,myFuns.nDataRowLength,0);
} fs.Close();
}
catch (Exception e)
{
ShowErrMessage(e.ToString() + "@" + "myFuns.SearchFile");
}
return "";
}
string s = sr.ReadLine();
sr.Close();
if (s.Trim().Equals("")) return;哦,一定要记住要把 File.OpenText("PD.ADB")-->PD.ADB 路径名称写全.如果这样不可以,再看一下是否一定要后缀名称为pd.txt .上面两种方法我都用过,pda是没有问题的
如果还有问题可以联系我[email protected]
string s = "";
string temp1 = "";
string temp2 = "";
string temp3 = "";
int k=0;
using (StreamReader sr = File.OpenText(FILE_NAME))
{
while ((s = sr.ReadLine()) != null)
{
switch(k)
{
case 0:
temp1 = s;
break;
case 1:
temp2 = s;
break;
case 2:
temp3 = s;
break;
}
k++;
}
}
"未处理的System.IO.FileNotFoundExecption"类型的异常出现在mscorlib.dll 中。其他信息: FileNotFoundException我也是试了好多方法来解决,结果还是无解!
在文件读取时,我用的是文件的相对路径.....
strFullAppPath = Path.GetDirectoryName(strFullAppName);
strFullFileName = Path.Combine(strFullAppPath, "data.xml");使用绝对路径就可以了.
这方法能否再细说一下,最近我是做程序一点感觉都没有啦...
谢谢!
string strFullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///","");
string strFullAppPath = Path.GetDirectoryName(strFullAppName);
string FileName = Path.Combine(strFullAppPath, "test.txt");
string TestString = "这是一个测试This is a Test";
System.Text.Encoding Encoding = System.Text.Encoding.GetEncoding("gb2312");
FileStream sw = File.OpenWrite(FileName);
sw.Write(Encoding.GetBytes(TestString),0,Encoding.GetByteCount(TestString));
sw.Close();上面的代码在执行文件路径下创建了一个"test.txt"文件,文件内容是"这是一个测试This is a Test"
//--show message box
public static string GetFullFilePath(string sFileName)
{
if (sFileName.Equals("")) return "";
string sFullAppFileName = Assembly.GetExecutingAssembly().GetName().CodeBase;
string sAppPath = Path.GetDirectoryName(sFullAppFileName);
string sRetFileName = Path.Combine(sAppPath,sFileName);
return sRetFileName;
}
如果你把文件放在可执行程序根目录下 操作如下: myFuns 是我得类名你可以不管他
myFuns.GetFullFilePath(myFuns.DATA_FILE_NAME)