获取运行时的动态目录

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;
}
}

随机推荐

  1. neo4j-jersey分嵌入式和服务式连接图形数据库

    原文载自:http://blog.csdn.net/yidian815/article/details/12887259 嵌入式: 引入neo4j依赖 <dependency> <g ...

  2. bat转exe工具 Bat To Exe Converter v2.4.7 绿色版

    一款非常小巧的工具,从它的名称便能知道它的功能:它能将BAT或CMD文件转换成 EXE 文件.使用它,你可以保护由自己开发的软件的软件代码,创建一个漂亮的图标,让软件看起来更专业. 下载地址: htt ...

  3. svn1.6在centos6下的使用

    版本 CentOS 6:svn 1.6.11 svn1.6版本的不足在于,每个目录递归存在.svn目录:从1.7开始就只有root节点目录存在.svn目录,和git一样了. 但是因为还在用CentOS ...

  4. py-faster-rcnn几个辅助脚本

    py-faster-rcnn本身代码很棒. 不过使用它的时候,还是需要自己写一些脚本,作为辅助. 1 所有.py文件顶部添加utf8编码声明.因为有时候需要添加中文注释,不声明编码会报错 #inser ...

  5. begin

    经历了一段时间的使用Github发表个人博客,我的感受就是很装逼,但是很麻烦--,因为都是自己手动弄的,还不如博客园方便,还有自己买了域名,但是SEO却提不上起,或者说压根就没有 --#,所以说,经过 ...

  6. Drop it

    FCC题目:队友该卖就卖,千万别舍不得. 让我们来丢弃数组(arr)的元素,从左边开始,直到回调函数return true就停止. 第二个参数,func,是一个函数.用来测试数组的第一个元素,如果返回 ...

  7. iOS 开发总结(下)

    来源:蝴蝶之梦天使 链接:http://www.jianshu.com/p/d333cf6ae4b0 四十.AFNetworking 传送 form-data 将JSON的数据,转化为NSData, ...

  8. 网页上获取的元素值,为什么类型,string

    <body> <input type="text" value='9'/><input type="text" value='30 ...

  9. Android SharedPreferences存储

    原创文章,转载请注明出处:http://www.cnblogs.com/baipengzhan/p/Android_SharedPreferences.html 一 概念 SharedPreferen ...

  10. Linux查看tomcat 控制台输出命令

    用远程登陆客户端登陆linux进入tomcat/logs/文件夹下键入指令:tail -f catalina.out