wFile.cs
using System; using System.IO; using System.Text; using System.Collections.Generic; public class WFile { public WFile() { } public static bool exist(string fileName) { return File.Exists(fileName); } public static bool space(char charValue) { return char.IsWhiteSpace(charValue); } public static string pathJoin(string dir, string file) { return Path.Combine( dir, file ); } public static void delete(string fileName) { File.Delete(fileName); } public static void create(string fileName) { Directory.CreateDirectory(fileName); } public static string parent(string fileName) { return Path.GetDirectoryName(fileName); } public static string getDocumentFolder() { return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } public static List<string> getDirectoryList(string fileName) { return new List<string>(Directory.EnumerateDirectories(fileName)); } public static List<string> getDirectoryList2(string fileName) { System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(fileName); foreach( System.IO.FileInfo file in dir.GetFiles() ) { //file.FullName //file.Extension } return new List<string>(); } public static void fileWriteBinary(string fileName, int intValue ) { using( FileStream fs = new FileStream(fileName, FileMode.CreateNew) ) { using( BinaryWriter w = new BinaryWriter(fs) ) { w.Write(intValue); } } } public static int fileReadBinary(string fileName ) { using( FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read) ) { using( BinaryReader r = new BinaryReader(fs) ) { return r.ReadInt32(); } } } public static void fileWriteText(string fileName, string strValue ) { using( StreamWriter sw = new StreamWriter(fileName) ) { sw.Write( strValue ); } } public void fileAppendText(string fileName, string strValue ) { using( StreamWriter sw = new StreamWriter(fileName, true) ) { sw.Write( strValue ); } } public static async void fileWriteTextAsync(string fileName, string strValue ) { using( StreamWriter sw = new StreamWriter(fileName) ) { await sw.WriteAsync( strValue ); } } public static string fileReadText(string fileName ) { using( StreamReader sr = new StreamReader(fileName) ) { return sr.ReadToEnd(); } } /* public static async void fileReadTextASync(string fileName ) { try { using( StreamReader sr = new StreamReader("TestFile.txt") ) { string line = await sr.ReadToEndAsync(); ResultBlock.Text = line; } } catch( FileNotFoundException ex ) { ResultBlock.Text = ex.Message; } } */ public static void fileWriteAllText(string fileName, string text) { File.WriteAllText( fileName, text); } public static void fileWriteAllText(string fileName, string[] lines) { File.WriteAllLines( fileName, lines); } public static char[] stringRead( string strValue, int len ) { using (StringReader sr = new StringReader(strValue)) { char[] b = new char[strValue.Length]; sr.Read(b, 0, 13); return b; } } public static string stringWrite() { StringBuilder sb = new StringBuilder(); using( StringWriter sw = new StringWriter(sb) ) { sw.Write("string1"); sw.Write("string2"); return sb.ToString(); } } }
댓글 없음:
댓글 쓰기