c# 常用的几个小方法
来源:互联网 发布:淘宝的数据分析 编辑:程序博客网 时间:2024/06/05 07:56
//日志保存
public static void logSave(String logPath, String message)
{String path = "log/getListByFile" + logPath;
if (Directory.Exists(path) == false)
{
Directory.CreateDirectory(path);
}
string filePath = path + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".log";
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
byte[] data1 = System.Text.Encoding.Default.GetBytes(message + "\n");
fs.Write(data1, 0, data1.Length);
fs.Flush();
fs.Close();
}
//判断文件存在
File.Exists(path)
//读取文件并遍历
public static void getListByFile(String path, out List<Dictionary<String, String>> list)
{
list = new List<Dictionary<String, String>>();
String[] lines = File.ReadAllLines(path);
foreach (String line in lines)
{
String[] lineArr = line.Split(' ');
Dictionary<String, String> latLonMap = new Dictionary<String, String>();
try
{
latLonMap.Add("lat", lineArr[6]);
latLonMap.Add("lon", lineArr[7]);
}
catch (ArgumentOutOfRangeException e)
{
logSave("", e.ToString());
continue;
}
list.Add(latLonMap);
}
}
//判断小数点后的位数,
public static String getStrByDouble(Double a)
{
String strDouble = a.ToString();
int result = strDouble.Length - strDouble.IndexOf('.') - 1;
if (result < 9)
{
strDouble = string.Format("{0:f9}", a);
}
return strDouble;
}
- c# 常用的几个小方法
- c#读写文件的几个小方法
- c# linq的几个常用方法
- c#自己总结的几个常用的小技巧
- 几个常用的方法
- 几个常用的小函数
- 几个常用的小接口
- c#常用的小函数和方法集
- 几个java常用的方法
- inventDimParm 常用的几个方法
- JFrame常用的几个方法
- js几个常用的方法
- map的几个常用方法
- sqlite的几个常用方法
- UITableView 常用的几个方法
- 字符串常用的几个方法
- jQuery的几个常用方法
- sqlite的几个常用方法
- 《WebGL编程指南》学习笔记——3.在Canvas中使用WebGL
- 用yum在centos7.3上安装mysql
- log4j配置实例,简单实用,我用来做模板的
- numpy.meshgrid
- NeedDownloadError: Need ffmpeg exe. 问题解决
- c# 常用的几个小方法
- [Leetcode] 529. Minesweeper 解题报告
- Linux vim操作
- React组件生命周期小结
- Spring Boot常用测试场景及分析
- vimrc配置文件(亲测,好用)
- 412. Fizz Buzz
- Java操作jdbc工具类
- mysql 数据安装后启用远程访问!