天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
2.5 KiB

using System;
using System.IO;
using System.Reflection;
using System.Text;
namespace QMAPP.WinForm
{
public static class IoHelper
{
public static string GetDllPath()
{
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
public static string GetFullPath(string rootPath, string path)
{
if (!Directory.Exists(rootPath))
Directory.CreateDirectory(rootPath);
if (!rootPath.EndsWith("\\"))
rootPath += "\\";
var fullPath = rootPath + path;
if (!Directory.Exists(fullPath))
Directory.CreateDirectory(fullPath);
return rootPath + path;
}
public static string GetFullFilename(string path, string filename, bool isLocal = true)
{
var str = string.Empty;
if (isLocal) str += GetDllPath() + "\\";
str += GetPath(path) + "\\" + filename;
return str;
}
public static string GetPath(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return path;
}
public static System.Text.Encoding GetFileEncodeType(string filename)
{
Encoding encoding;
using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open,
System.IO.FileAccess.Read))
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
Byte[] buffer = br.ReadBytes(2);
if (buffer[0] >= 0xEF)
{
if (buffer[0] == 0xEF && buffer[1] == 0xBB)
{
encoding = System.Text.Encoding.UTF8;
}
else if (buffer[0] == 0xFE && buffer[1] == 0xFF)
{
encoding = System.Text.Encoding.BigEndianUnicode;
}
else if (buffer[0] == 0xFF && buffer[1] == 0xFE)
{
encoding = System.Text.Encoding.Unicode;
}
else
{
encoding = System.Text.Encoding.Default;
}
}
else
{
encoding = System.Text.Encoding.Default;
}
fs.Close();
}
return encoding;
}
}
}