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;
}
}
随机推荐
- 为什么要在游戏开发中使用ECS模式
http://www.richardlord.net/blog/why-use-an-entity-framework Why use an entity system framework for g ...
- Mongodb的安装使用
1.下载 最好不要去.com的那个网站下载: 各个版本的下载地址: http://dl.mongodb.org/dl/win32/x86_64 2.压缩包版本: 下载压缩包版本,目录结构如图: ...
- [翻译]ES 提案: global
Jordan Harband 的 ECMAScript 提案“global”现在处于第三阶段.该提案提供了一种新的用于访问全局对象的标准方式. 全局对象的引用 下面是常用的几种引用全局对象的方式: 全 ...
- 【BZOJ 4580】【Usaco2016 Open】248
http://www.lydsy.com/JudgeOnline/problem.php?id=4580 区间dp,f(i,j)表示区间[i,j]全部合成一个数,这个数是多少. 可以归纳证明[i,j] ...
- java script 基础知识
方法:提供信息 函数去处理 给出一个结果 字符类型. 字符提前赋类型 int i=1; money x; float;datetime; decimal;var 万用类型 var a = 1; 1赋值 ...
- Java中private、protected、public和default的区别
public: 具有最大的访问权限,可以访问任何一个在classpath下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. protected: 主要的作用就是用来保护子 ...
- Error Domain=NSURLErrorDomain Code=-999 “The operation couldn’t be completed.
转:http://www.wangzhengdong.com/blog/error-domainnsurlerrordomain-code-999-the-operation-couldnt-be-c ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- iOS静态库开发中对Bitcode的支持
1.bitcode bitcode是LLVM编译器将C/C++/OC/Swift等前端变成语言编译成多种不同芯片上的机器指令过程中的中间代码.并且这个中间代码是CPU无关的. 原本我们的APP里要包含 ...
- Java开发实践 集合框架 全面分析
http://www.open-open.com/lib/view/open1474167415464.html