fork download
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. public class DiskIsNotEnoughFreeSpace : IOException
  10. {
  11. public DiskIsNotEnoughFreeSpace(string msg)
  12. : base(msg)
  13. {
  14.  
  15. }
  16. }
  17.  
  18. public class FileStreamEx : FileStream
  19. {
  20.  
  21.  
  22. public FileStreamEx(string path, FileMode mode, FileAccess access) : base(path, mode,access)
  23. {
  24.  
  25. }
  26.  
  27. public override void WriteByte(byte value)
  28. {
  29. // ドライブ名取得
  30. DriveInfo driveinfo = new DriveInfo(Path.GetPathRoot(this.Name));
  31.  
  32. if (driveinfo.AvailableFreeSpace < 1)
  33. throw new DiskIsNotEnoughFreeSpace("HDDに空きがありません");
  34.  
  35. base.WriteByte(value);
  36. // 残り3kbちょっきしでIOException
  37. }
  38. }
  39.  
  40. class Program
  41. {
  42. static void Main(string[] args)
  43. {
  44. using (var fs2 = new FileStream(@"R:\test.temp", FileMode.Create))
  45. {
  46. fs2.SetLength(9275179686);
  47.  
  48.  
  49. FileStreamEx fs = new FileStreamEx(@"R:\test.byte", FileMode.Append, FileAccess.Write);
  50.  
  51. while (true)
  52. {
  53.  
  54. fs.WriteByte(64);
  55. }
  56. }
  57.  
  58. }
  59. }
  60. }
  61.  
Runtime error #stdin #stdout #stderr 0.03s 26848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.UnauthorizedAccessException: Access to the path "/home/ncWQ9p/R:\test.temp" is denied.
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode)
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/home/ncWQ9p/R:\test.temp" is denied.
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode)
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0