本文整理汇总了C#中FileInfo.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.OpenRead方法的具体用法?C# FileInfo.OpenRead怎么用?C# FileInfo.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.OpenRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
public static void Decompress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension,
// for example "doc" from report.doc.cmp.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length
- fi.Extension.Length);
//Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
using (DeflateStream Decompress = new DeflateStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile);
Console.WriteLine("Decompressed: {0}", fi.Name);
}
}
}
}
示例2: Decompress
public static void Decompress(FileInfo archFile, out String szOutFile)
{
Logger.Enter();
using (FileStream archFileStream = archFile.OpenRead())
{
String currentFileName = archFile.FullName;
String newFileName = currentFileName.Remove(
currentFileName.Length - archFile.Extension.Length);
using (FileStream normalFileStream = File.Create(newFileName))
{
using (GZipStream decompressionStream = new GZipStream(archFileStream, CompressionMode.Decompress))
{
byte[] buffer = new byte[1024];
int nRead;
while ((nRead = decompressionStream.Read(buffer, 0, buffer.Length)) > 0)
{
normalFileStream.Write(buffer, 0, nRead);
}
szOutFile = newFileName;
Console.WriteLine("Decompressed: {0}", archFile.Name);
}
}
}
Logger.Leave();
}
示例3: Compress
public static void Compress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Prevent compressing hidden and already compressed files.
if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
!= FileAttributes.Hidden & fi.Extension != ".cmp")
{
// Create the compressed file.
using (FileStream outFile =
File.Create(fi.FullName + ".cmp"))
{
using (DeflateStream Compress =
new DeflateStream(outFile,
CompressionMode.Compress))
{
// Copy the source file into
// the compression stream.
inFile.CopyTo(Compress);
Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
fi.Name, fi.Length.ToString(), outFile.Length.ToString());
}
}
}
}
}
示例4: ReadFile
private void ReadFile()
{
FileInfo fi = new FileInfo(Application.dataPath + "/Data/Data.txt");
if (fi == null) return;
StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8);
_path = sr.ReadToEnd();
}
示例5: getBinaryFromFile
public static byte[] getBinaryFromFile(FileInfo f)
{
byte[] buffer = null;
if (f.Exists)
{
try
{
buffer = new byte[f.OpenRead().Length];
f.OpenRead().Read(buffer, 0, (int)f.OpenRead().Length);
}
catch (Exception ex)
{
LoggerFacade.Log(ex);
}
}
return buffer;
}
示例6: FileAccessTest
public static int FileAccessTest (String file_name)
{
FileInfo fi = new FileInfo (file_name);
FileStream fs = fi.OpenRead ();
Console.WriteLine (fi.Length);
Byte [] bt = new byte [fi.Length];
return fs.Read (bt, 0, (int) fi.Length);
}
示例7: ReadcsvString
static string ReadcsvString()
{
FileInfo fi = new FileInfo(Application.dataPath + "/Resources/EnemySpoawn.csv");
using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)) {
return sr.ReadToEnd();
}
}
示例8: read
// 読み込み
public void read()
{
FileInfo fi = new FileInfo(Application.dataPath+"/test.txt");
StreamReader sr = new StreamReader(fi.OpenRead());
while( sr.Peek() != -1 ){
print( sr.ReadLine() );
}
sr.Close();
}
示例9: read
// テキストの読み込み
public void read()
{
FileInfo fi = new FileInfo(Application.dataPath + "/" + filepath);
StreamReader sr = new StreamReader(fi.OpenRead());
int i = 0;
while (sr.Peek() != -1)
{
scenarios[i] = sr.ReadLine();
i++;
}
i = 0;
sr.Close();
}
示例10: _readFile
// データ読み込
void _readFile()
{
// FileReadTest.txtファイルを読み込む
FileInfo fi = new FileInfo(Application.dataPath + "/" + "data.csv");
try {
// 一行毎読み込み
using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)){
guitxt = sr.ReadToEnd();
}
} catch (Exception /* e */ ){
// 改行コード
guitxt += SetDefaultText();
}
}
示例11: ReadFile
//--------------------
// ファイル読み込み
//--------------------
string ReadFile( string fileName )
{
string strTemp = "";
FileInfo fi = new FileInfo( Application.dataPath + fileName );
try {
using( StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8) ) {
strTemp = sr.ReadToEnd();
}
} catch (Exception e){
Debug.LogException ( e );
strTemp = "";
}
return( strTemp );
}
示例12: ReadJSON
public static SimpleJSON.JSONNode ReadJSON(string path)
{
var fullPath = Path.Combine(Application.streamingAssetsPath, path);
var fileInfo = new FileInfo(fullPath);
using ( var stream = new StreamReader(fileInfo.OpenRead(), System.Text.Encoding.UTF8) ) {
try {
var jsonStr = stream.ReadToEnd();
var json = SimpleJSON.JSON.Parse(jsonStr);
return json;
} catch (System.Exception e) {
Debug.LogError(e.StackTrace);
}
}
return null;
}
示例13: Main
public static void Main(string[] args)
{
FileInfo fl = new FileInfo(@"..\..\ReadBinary.txt");
Stream strm = fl.OpenRead();
int iNext;
do
{
iNext = strm.ReadByte();
if (iNext != -1)
Console.WriteLine(iNext.ToString());
}
while (iNext != -1);
strm.Close();
Console.WriteLine("All done.");
Console.ReadLine();
}
示例14: ReadFileString
// ファイルを読み込んで内容を文字列で戻す.
public static string ReadFileString(string path)
{
string s;
#if !UNITY_WEBPLAYER
FileInfo fi = new FileInfo(Application.dataPath + "/" + path);
using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8))
{
s = sr.ReadToEnd();
}
#else
Debug.LogError("WebPlayerではOpenReadは使えません.");
#endif
return s;
}
示例15: Main
public static void Main (string [] args)
{
if (args.Length == 0 || args.Length > 3) {
Console.WriteLine ("Usage: zipmark FILE [ITERATIONS] [BLOCKSIZE]");
return;
}
string filename = args [0];
FileInfo file = new FileInfo (filename);
if (!file.Exists) {
Console.WriteLine ("Couldn't find file {0}", filename);
return;
}
FileStream fs = file.OpenRead ();
byte [] raw = new byte [file.Length];
int count = fs.Read (raw, 0, (int)file.Length);
fs.Close ();
if (count != file.Length) {
Console.WriteLine ("Couldn't read file {0}", filename);
return;
}
Deflater def = new Deflater (Deflater.BEST_COMPRESSION, false);
Inflater inf = new Inflater (false);
// 1. Count deflated size
int cooked_size = Deflate (def, raw, null);
byte [] cooked = new byte [cooked_size];
// 2. Deflate & Inflate
if (args.Length > 1)
Iterations = Int32.Parse (args [1]);
if (args.Length > 2)
BlockSize = Int32.Parse (args [2]);
for (int i = 0; i < Iterations; ++ i) {
Deflate (def, raw, cooked);
Inflate (inf, cooked, raw);
}
return;
}