```
// <summary>?
??????? /// 創建固定大小的臨時文件?
??????? /// </summary>?
??????? /// <param name="fileName">文件名</param>?
??????? /// <param name="fileSize">文件大小</param>?
??????? /// <param name="overwrite">允許覆寫:可以覆蓋掉已經存在的文件</param>?
??????? public static void CreateFixedSizeFile(string fileName, long fileSize)
??????? {
??????????? //驗證參數?
??????????? if (string.IsNullOrEmpty(fileName) || new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }.Contains(
??????????????????? fileName[fileName.Length - 1]))
??????????????? throw new ArgumentException("fileName");
??????????? if (fileSize < 0) throw new ArgumentException("fileSize");
??????????? //創建目錄?
??????????? string dir = Path.GetDirectoryName(fileName);
??????????? if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
??????????????? Directory.CreateDirectory(dir);
??????????? //創建文件?
??????????? FileStream fs = null;
??????????? try
??????????? {
??????????????? fs = new FileStream(fileName, FileMode.Create);
??????????????? fs.SetLength(fileSize); //設置文件大小?
??????????? }
??????????? catch
??????????? {
??????????????? if (fs != null)
??????????????? {
??????????????????? fs.Close();
??????????????????? File.Delete(fileName); //注意,若由fs.SetLength方法產生了異常,同樣會執行刪除命令,請慎用overwrite:true參數,或者修改刪除文件代碼。?
??????????????? }
??????????????? throw;
??????????? }
??????????? finally
??????????? {
??????????????? if (fs != null) fs.Close();
??????????? }
??????? }
??????? /// <summary>
??????? /// 讀取大文件用,讀取文件前面指定長度字節數
??????? /// </summary>
??????? /// <param name="filePath">文件路徑</param>
??????? /// <param name="readByteLength">讀取長度,單位字節</param>
??????? /// <returns></returns>
??????? public byte[] ReadBigFile(string filePath,int readByteLength)
??????? {?
??????????? FileStream stream = new FileStream(filePath,FileMode.Open);
??????????? byte[] buffer = new byte[readByteLength];
??????????? stream.Read(buffer, 0, readByteLength);
??????????? stream.Close();
??????????? stream.Dispose();
??????????? return buffer;
??????????? //string str = Encoding.Default.GetString(buffer) //如果需要轉換成編碼字符串的話
??????? }
??????? /// <summary>
??????? /// 普通文件讀取方法
??????? /// </summary>
??????? /// <param name="path"></param>
??????? /// <returns></returns>
??????? public string ReaderFile(string path)
??????? {
??????????? string fileData = string.Empty;
??????????? ///讀取文件的內容?????
??????????? StreamReader reader = new StreamReader(path, Encoding.Default);
??????????? fileData = reader.ReadToEnd();
??????????? reader.Close();
??????????? reader.Dispose();
??????????? return fileData;
??????? }
```
原文鏈接:https://blog.csdn.net/u013628121/article/details/52577702
- C#
- 基礎 System
- 命名規范
- 變量
- 數據類型
- 值類型
- 簡單類型
- 整數類型
- 字符類型
- 浮點類型
- 布爾類型
- 枚舉類型
- 結構體類型
- 引用類型
- 類類型
- 對象(Object)類型
- 字符串(String)類型
- 方法屬性
- 動態(Dynamic)類型
- 數組類型
- 接口Interface
- 委托類型delegate
- 裝箱和拆箱
- 指針類型
- 值類型與引用類型的區別
- Var類型
- 類型轉換
- 隱式轉換
- 顯式轉換
- 常量
- 常用函數
- 流程控制
- 循環
- 跳轉語句
- 數組
- 數組查找
- 添加組元素
- 復制與克隆數組
- 刪除數組元素
- 數組排序與反轉
- 數組排序
- 冒泡排序
- 直接插入排序
- 選擇排序法
- 數組對象
- 哈希表
- 其他
- 遞歸
- 屬性與方法及方法重載
- 結構與類
- 類
- 構造函數與析構函數
- 繼承
- 多態
- 泛型
- demo
- 漢字字符(串)比較
- 創建指定大小文件與讀取大文件
- 小截屏軟件功能
- 子窗體返回主窗體
- 判斷是否為數字
- 獲得字符串實際長度(包括中文字符)
- unity
- script腳本
- 腳本的生命周期
- 調試
- Unity Manual5.4
- Unity手冊
- Working In Unity
- Unity 2D
- Graphics(圖形)
- Physics(物理系統)
- Scripting(腳本)
- Multiplayer and Networking(多玩家和聯網)
- Audio(音頻)
- Animation(動畫)
- UI
- Navigation and Pathfinding(導航和尋路)
- Unity Services(Unity服務)
- Virtual Reality(虛擬現實VR)
- Open-source repositories(開源代碼庫)
- Platform-specific(特定于平臺的信息)
- Legacy Topics(舊版主題)
- Expert Guides(專家指南)
- 重要的類
- Object
- GameObject(重要)
- Component
- Transform(重要)
- Rigidbody
- ParticleSystem
- Behaviour
- Camera
- Animator
- AudioSource
- Animation
- AudioListener
- Light
- MonoBehaviour事件行為(重要)
- Terrain
- Collider
- Renderer
- Texture
- Mesh
- material
- Time
- Prefab預制件
- 功能demo
- 層級未知查找子物體
- 查找hp最小的敵人
- 查找最近的敵人
- 小項目之英雄無敵
- 界面操作
- Scene窗口
- Game窗口
- project窗口
- Hierarchy窗口
- 動畫
- Animation重要API
- 2D
- Sprite(creator) Sprite Renderer
- Sprite Editor
- Sprite Packer(遺留功能)
- 排序組組件
- 切片精靈
- 精靈遮罩
- 精靈圖集
- Tilemap
- 2D物理系統
- 全局設置(Project setting)
- 2D剛體(Rigidbody 2D)
- 碰撞(事件)消息
- 2D碰撞體(Collider 2D)
- 2D圓形碰撞體(Circle Collider 2D)
- 2D盒型碰撞體(BoxCollider 2D)
- 2D多邊形碰撞體( Polygon Collider 2D)
- 2D邊界碰撞體(EdgeCollider 2D)
- 2D膠囊碰撞體(CapsuleCollider 2D)
- 2D復合碰撞體(Composite Collider 2D)
- 2D物理材質(摩擦和彈性)(Physics Material 2D)
- 2D關節
- 2D距離關節(Distance Joint 2D)
- 2D固定關節(Fixed Joint 2D)
- 2D摩擦關節(Friction Joint 2D)
- 2D鉸鏈關節(Hinge Joint 2D)
- 2D相對關節(Relative Joint 2D)
- 2D滑動關節(Slider Joint 2D)
- 2D彈簧關節(Spring Joint 2D)
- 2D目標關節(Target Joint 2D)
- 2D車輪關節(Wheel Joint 2D)
- 2D恒定力(Constant Force 2D)
- 2D 效應
- 2D區域效應(AreaEffector 2D)
- 2D浮力效應(BuoyancyEffector 2D)
- 2D點效應(PointEffector 2D)
- 2D平臺效應(PlatformEffector 2D)
- 2D表面效應(SurfaceEffector 2D)
- 精靈動畫
- 2D動畫事件
- 重要類
- rigidbody2d
- 小竅門
- Unity中如何查找腳本掛載在哪個物體上