.NETプログラミング

テキストファイルを読む

using System.IO;
public class TextFromFile 
{
   private const string FILE_NAME = "MyFile.txt";
   public static void Main(String[] args) 
   {
       if (!File.Exists(FILE_NAME)) 
       {
           Console.WriteLine("{0} does not exist.", FILE_NAME);
           return;
       }
       using (StreamReader sr = File.OpenText(FILE_NAME))
       {
           String input;
           while ((input=sr.ReadLine())!=null) 
           {
               Console.WriteLine(input);
           }
           Console.WriteLine ("The end of the stream has been reached.");
           sr.Close();
       }
   }
}

ファイルサイズ取得

System.IO.FileInfo fi = new System.IO.FileInfo(filePath);
//ファイルのサイズを取得
long filesize = fi.Length;

ディスク空き容量の取得

ZIP書庫の作成、解凍

ZipEntry.getSize()で-1が返って来ることがある件

一時ファイル、Tmpファイル

ファイルの列挙

ファイルのコピー、削除、移動、属性操作

NTFSの機能で暗号化

ファイル・フォルダの変更を監視

ファイルの属性判定

非同期ファイルI/O

パス文字列操作

ファイル操作

各種フォルダ取得

デスクトップフォルダ取得

System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);

または

System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);

この二つの違いは、上が仮想フォルダで下が物理フォルダとのことなのだが、実際に試すと同じ結果になるようで、正直よくわからない

My Document

System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

Tempフォルダのパス取得

Path.GetTempPath()

カレントディレクトリ取得

string stCurrentDir = System.IO.Directory.GetCurrentDirectory();

実行ファイルのPath取得

DLLのPath取得

string m_Path = Assembly.GetExecutingAssembly().CodeBase ;
string m_Dir = System.IO.Path.GetDirectoryName(m_Path);

これ↓だとキャッシュディレクトリが返る

path = this.GetType().Module.FullyQualifiedName;

CSV処理


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2009-04-12 (日) 07:32:56