forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileSystemHelper.cs
56 lines (51 loc) · 1.62 KB
/
FileSystemHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#if UNITY_EDITOR
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// Helper functions for file I/O
/// </summary>
public static class FileSystemHelper
{
public static void WriteBytesToLocalFile(string filename, byte[] content)
{
try
{
var fs = new System.IO.FileStream(filename, System.IO.FileMode.Create);
var bw = new System.IO.BinaryWriter(fs);
bw.Write(content);
bw.Close();
fs.Close();
}
catch (System.Exception ex)
{
Debug.LogError("Error writing to file: " + ex.ToString());
}
}
public static byte[] ReadBytesFromLocalFile(string fullPath)
{
var path = fullPath;
byte[] result = null;
try
{
var fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
var br = new System.IO.BinaryReader(fs);
if (fs.Length > int.MaxValue)
{
throw new System.ArgumentOutOfRangeException();
}
result = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
}
catch (System.Exception ex)
{
Debug.LogError("Read file exception: " + ex.ToString());
}
return result;
}
}
}
#endif