init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.IO {
|
||||
|
||||
/// <summary>
|
||||
/// 封装了文件常用操作方法
|
||||
/// </summary>
|
||||
public class File {
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件的内容(采用UTF8编码)
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <returns>文件的内容</returns>
|
||||
public static String Read( String absolutePath ) {
|
||||
return Read( absolutePath, Encoding.UTF8 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以某种编码方式,读取文件的内容
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="encoding">编码方式</param>
|
||||
/// <returns>文件的内容</returns>
|
||||
public static String Read( String absolutePath, Encoding encoding ) {
|
||||
using (StreamReader reader = new StreamReader( absolutePath, encoding )) {
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件各行内容(采用UTF8编码),以数组形式返回
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <returns>文件各行内容</returns>
|
||||
public static String[] ReadAllLines( String absolutePath ) {
|
||||
return ReadAllLines( absolutePath, Encoding.UTF8 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以某种编码方式,读取文件各行内容(采用UTF8编码),以数组形式返回
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="encoding">编码方式</param>
|
||||
/// <returns>文件各行内容</returns>
|
||||
public static String[] ReadAllLines( String absolutePath, Encoding encoding ) {
|
||||
ArrayList list = new ArrayList();
|
||||
using (StreamReader reader = new StreamReader( absolutePath, encoding )) {
|
||||
String str;
|
||||
while ((str = reader.ReadLine()) != null) {
|
||||
list.Add( str );
|
||||
}
|
||||
}
|
||||
return (String[])list.ToArray( typeof( String ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串写入某个文件中(采用UTF8编码)
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="fileContent">需要写入文件的字符串</param>
|
||||
public static void Write( String absolutePath, String fileContent ) {
|
||||
Write( absolutePath, fileContent, Encoding.UTF8 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串写入某个文件中(需要指定文件编码方式)
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="fileContent">需要写入文件的字符串</param>
|
||||
/// <param name="encoding">编码方式</param>
|
||||
public static void Write( String absolutePath, String fileContent, Encoding encoding ) {
|
||||
using (StreamWriter writer = new StreamWriter( absolutePath, false, encoding )) {
|
||||
writer.Write( fileContent );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文件
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
public static void Delete( String absolutePath ) {
|
||||
System.IO.File.Delete( absolutePath );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <returns></returns>
|
||||
public static Boolean Exists( String absolutePath ) {
|
||||
return System.IO.File.Exists( absolutePath );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移动文件
|
||||
/// </summary>
|
||||
/// <param name="sourceFileName">原来的路径</param>
|
||||
/// <param name="destFileName">需要挪到的新路径</param>
|
||||
public static void Move( String sourceFileName, String destFileName ) {
|
||||
System.IO.File.Move( sourceFileName, destFileName );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝文件(如果目标存在,不覆盖)
|
||||
/// </summary>
|
||||
/// <param name="sourceFileName">原来的路径</param>
|
||||
/// <param name="destFileName">需要挪到的新路径</param>
|
||||
public static void Copy( String sourceFileName, String destFileName ) {
|
||||
System.IO.File.Copy( sourceFileName, destFileName, false );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝文件
|
||||
/// </summary>
|
||||
/// <param name="sourceFileName">原来的路径</param>
|
||||
/// <param name="destFileName">需要挪到的新路径</param>
|
||||
/// <param name="overwrite">如果目标存在,是否覆盖</param>
|
||||
public static void Copy( String sourceFileName, String destFileName, Boolean overwrite ) {
|
||||
System.IO.File.Copy( sourceFileName, destFileName, overwrite );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将内容追加到文件中(采用UTF8编码)
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="fileContent">需要追加的内容</param>
|
||||
public static void Append( String absolutePath, String fileContent ) {
|
||||
Append( absolutePath, fileContent, Encoding.UTF8 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将内容追加到文件中
|
||||
/// </summary>
|
||||
/// <param name="absolutePath">文件的绝对路径</param>
|
||||
/// <param name="fileContent">需要追加的内容</param>
|
||||
/// <param name="encoding">编码方式</param>
|
||||
public static void Append( String absolutePath, String fileContent, Encoding encoding ) {
|
||||
using (StreamWriter writer = new StreamWriter( absolutePath, true, encoding )) {
|
||||
writer.Write( fileContent );
|
||||
}
|
||||
}
|
||||
|
||||
//public static void Zip( String sourceFileName ) {
|
||||
// Zip( sourceFileName, sourceFileName + ".zip" );
|
||||
//}
|
||||
|
||||
//public static void Zip( String sourceFileName, String destFileName ) {
|
||||
// throw new Exception( "Zip 方法未实现" );
|
||||
//}
|
||||
|
||||
//public static void UnZip( String sourceFileName ) {
|
||||
// throw new Exception( "UnZip 方法未实现" );
|
||||
//}
|
||||
|
||||
//public static void UnZip( String sourceFileName, String destFilePath ) {
|
||||
// throw new Exception( "UnZip 方法未实现" );
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Zhaizj.Framework.Web;
|
||||
|
||||
namespace Zhaizj.Framework.IO {
|
||||
|
||||
internal class LinuxPath : PathTool {
|
||||
|
||||
public override String CombineAbs( String[] arrPath ) {
|
||||
|
||||
if (arrPath.Length == 0) return "";
|
||||
|
||||
String result = arrPath[0];
|
||||
for (int i = 1; i < arrPath.Length; i++) {
|
||||
if (strUtil.IsNullOrEmpty( arrPath[i] )) continue;
|
||||
result = strUtil.Join( result, arrPath[i].Replace( "\\", "/" ) );
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public override String Map( String path ) {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( path )) return "";
|
||||
|
||||
if (SystemInfo.IsWeb == false) {
|
||||
|
||||
return strUtil.Join( AppDomain.CurrentDomain.BaseDirectory, path );
|
||||
}
|
||||
else {
|
||||
|
||||
String str = path;
|
||||
if (path.ToLower().StartsWith( SystemInfo.ApplicationPath ) == false)
|
||||
str = strUtil.Join( SystemInfo.ApplicationPath, path );
|
||||
|
||||
return HttpContext.Current.Server.MapPath( path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Zhaizj.Framework.Web;
|
||||
using System.Web;
|
||||
|
||||
namespace Zhaizj.Framework.IO {
|
||||
|
||||
internal abstract class PathTool {
|
||||
|
||||
public abstract String CombineAbs( String[] arrPath );
|
||||
public abstract String Map( String path );
|
||||
|
||||
public static PathTool getInstance() {
|
||||
if (SystemInfo.IsWindows) return new WindowsPath();
|
||||
return new LinuxPath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// bin 的绝对路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static String GetBinDirectory() {
|
||||
if (SystemInfo.IsWeb) {
|
||||
return HttpRuntime.BinDirectory;
|
||||
}
|
||||
|
||||
return AppDomain.CurrentDomain.BaseDirectory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Zhaizj.Framework.Web;
|
||||
|
||||
namespace Zhaizj.Framework.IO {
|
||||
|
||||
internal class WindowsPath : PathTool {
|
||||
|
||||
public override String CombineAbs( String[] arrPath ) {
|
||||
|
||||
if (arrPath.Length == 0) return "";
|
||||
|
||||
String result = arrPath[0];
|
||||
for (int i = 1; i < arrPath.Length; i++) {
|
||||
if (strUtil.IsNullOrEmpty( arrPath[i] )) continue;
|
||||
result = strUtil.Join( result, arrPath[i].Replace( "/", "\\" ), "\\" );
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public override String Map( String path ) {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( path )) return "";
|
||||
|
||||
if (SystemInfo.IsWeb == false) {
|
||||
|
||||
return strUtil.Join( AppDomain.CurrentDomain.BaseDirectory, path.Replace( "/", "\\" ), "\\" );
|
||||
}
|
||||
else {
|
||||
|
||||
String str = path;
|
||||
if (path.ToLower().StartsWith( SystemInfo.ApplicationPath ) == false)
|
||||
str = strUtil.Join( SystemInfo.ApplicationPath, path );
|
||||
|
||||
return HttpContext.Current.Server.MapPath( str );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Zhaizj.Framework.IO;
|
||||
|
||||
namespace Zhaizj.Framework {
|
||||
|
||||
/// <summary>
|
||||
/// 封装了文件常用操作方法
|
||||
/// </summary>
|
||||
public class file : File {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user