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. }
  37. }
  38.  
  39. class Program
  40. {
  41. static void Main(string[] args)
  42. {
  43. FileStreamEx fs = new FileStreamEx(@"R:\test.byte", FileMode.Append, FileAccess.Write);
  44.  
  45. while (true)
  46. {
  47.  
  48. fs.WriteByte(64);
  49. }
  50.  
  51. }
  52. }
  53. }
  54.  
Runtime error #stdin #stdout #stderr 0.03s 26840KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.UnauthorizedAccessException: Access to the path "/home/QR9mMb/R:\test.byte" 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, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0 
  at ConsoleApplication1.FileStreamEx..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) ConsoleApplication1.FileStreamEx:.ctor (string,System.IO.FileMode,System.IO.FileAccess)
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/home/QR9mMb/R:\test.byte" 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, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0 
  at ConsoleApplication1.FileStreamEx..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) ConsoleApplication1.FileStreamEx:.ctor (string,System.IO.FileMode,System.IO.FileAccess)
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0