C# I/O
获取运行时的动态目录
private static string GetDataDir_Data()
{
var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
string startDirectory = null;
if (parent != null)
{
var directoryInfo = parent.Parent;
if (directoryInfo != null)
{
startDirectory = directoryInfo.FullName;
}
}
else
{
startDirectory = parent.FullName;
}
return Path.Combine(startDirectory, "Data\\");
}
//参考之Aspose.Words-for-.NET-master
//其他
string d2 = AppDomain.CurrentDomain.BaseDirectory;
I/O操作之文件,目录删除
public void CleanTempPath(TCPRptParamInfo param)
{
string TempPath = ConfigHelper.ReadConfig("TempPath");
string returnStr = TempPath + "\\" + param.SubTempDirectory + "\\"; if (Directory.Exists(returnStr))
{
FileInfo[] fi = new DirectoryInfo(returnStr).GetFiles();
int fileLenght = fi.Length;
for (int i = ; i < fileLenght; i++)
{
fi[i].Delete();
}
//Directory.Delete(returnStr); //删目录,非空目录不能直接删除
}
}
if (Directory.Exists(returnStr))
{
Directory.Delete(returnStr,true);//直接删除非空目录
}
读文本方式之一
string dataDir = AppDomain.CurrentDomain.BaseDirectory; //Get Current Directory StreamReader srPerson = File.OpenText(FaleName1);//文本文件完整路径
StreamReader strData = File.OpenText(dataDir + "data.txt");
while (!strData.EndOfStream)
{
string textLine = srPerson.ReadLine();
//TODO
}
读文本方式之二
using System.IO; string dataPath = GetMaterialPath(param, DocType.LeaderAttribute) + "data.txt";
string configstr = System.IO.File.ReadAllText(dataPath, Encoding.Default); //核心方法:读文本方式之一
Dictionary<string, string> allConfig = ConfigHelper.ParseConfigString(configstr); public static class ConfigHelper
{
public static string ReadConfig(string key)
{
return System.Configuration.ConfigurationManager.AppSettings[key];
} public static Dictionary<string, string> ParseConfigString(string config)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
string[] array = config.Split(new char[]
{
'■'//行结束标记
});
string[] array2 = array;
for (int i = ; i < array2.Length; i++)
{
string text = array2[i];
string[] array3 = text.Split(new char[]
{
':'
});
if (array3.Length == )
{
dictionary.Add(array3[].Trim(), array3[].Trim());
}
else
{
dictionary.Add(text.Trim(), null);
}
}
return dictionary;
}
}
随机推荐
- 【原】Spark之机器学习(Python版)(二)——分类
写这个系列是因为最近公司在搞技术分享,学习Spark,我的任务是讲PySpark的应用,因为我主要用Python,结合Spark,就讲PySpark了.然而我在学习的过程中发现,PySpark很鸡肋( ...
- 《Redis入门指南(第二版)》读书思考总结之Redis五大数据类型
热身:系统级命令 1. 获得符合规则的键名列表 KEYS pattern 模式匹配 产品的缓存:product+"."+....; => keys product* 订单的 ...
- 聊聊 C 语言中的 sizeof 运算
聊聊 sizeof 运算 在这两次的课上,同学们已经学到了数组了.下面几节课,应该就会学习到指针.这个速度的确是很快的. 对于同学们来说,暂时应该也有些概念理解起来可能会比较的吃力. 先说一个概念叫内 ...
- express不是内部或外部命令
网上找了一下原因,是因为express在4.0以后把命令工具单独分出来了,所以安装完express后,还得再安装express-generator: 如果不是采用的全局安装,则需要把 "安装 ...
- [筆記] Ubuntu Linux 使用 apt-get 指令移除軟體並清理遺留的垃圾
This is come from http://blog.lyhdev.com/2013/01/ubuntu-linux-apt-get.html 在 Ubuntu 下移除某個軟體套件,使用的 ...
- 使用css3做钟表
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MVC其实很简单(Django框架)
Django框架MVC其实很简单 让我们来研究一个简单的例子,通过该实例,你可以分辨出,通过Web框架来实现的功能与之前的方式有何不同. 下面就是通过使用Django来完成以上功能的例子: 首先,我们 ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
- 页面局部跳转(iframe)
<script type="text/javascript"> function show() { document.getElementById("ff&q ...
- 关于delphi7的四舍五入
round 函数是银行用的 采用了 四舍六入5留偶 网上找到了个实现方法 先乘1000,用Trunc取整,除10取余,余数再取整,如果大于5,进位,小于5不进位. 函数就好写了 现在只写一个保留两 ...