.NET/バイト配列にファイルの内容をすべて読み込む
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* バイナリファイルをバイト配列にすべてを読み込む [#f7d99a...
バイナリファイルをバイト配列にすべてを読み込むメソッド ''...
電文ファイルなど、バイト配列に展開し操作したい場合など便...
#contents
* 関連サイト [#p35daca7]
-[[Microsoft .NET | File.ReadAllBytes(String) メソッド>ht...
-[[Microsoft .NET | File.WriteAllBytes(String, Byte[]) メ...
#htmlinsert(windev-top.html)
* 関連記事 [#o2425495]
-[[バイナリーファイルの作成・リード・ライト(バイト単位の...
* 動作確認環境 [#kcddeddc]
-Windows 10 ver.1909
-Visual Studio 2019
-.NET Core
-コンソールアプリケーション
* File.readallbytesサンプルコード [#k4ec2744]
本サンプルコードでは、 File.WriteAllBytes メソッドを使っ...
File.readallbytes メソッドで File.WriteAllBytes メソッド...
作成するファイルは、デスクトップに出力されます。
+ File.WriteAllBytes でファイルを作成し書き込み。
+ File.ReadAllBytes で 作成したファイルを読み込み、値を16...
** C# [#acaf2e56]
#ref(Program.cs)
using System;
class Program
{
static void Main(string[] args)
{
// Desktop path
string desktopPath = System.Environment.GetFolde...
// Read and Write filename
var filename = System.IO.Path.Combine(desktopPat...
// Output byte data
byte[] outBytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9...
// Write file
System.IO.File.WriteAllBytes(filename, outBytes);
// Read file and hex output
byte[] inBytes = System.IO.File.ReadAllBytes(fil...
for (int i = 1; i <= inBytes.Length; i++)
{
Console.WriteLine("{0} : {1:X}", i - 1, inBy...
}
}
}
** Visual Basic [#e6236899]
#ref(Program.vb)
Imports System
Module Program
Sub Main(args As String())
'Desktop path
Dim desktopPath As String = System.Environment.G...
'Read and Write filename
Dim filename = System.IO.Path.Combine(desktopPat...
'Output byte data
Dim outBytes As Byte() = {0, 1, 2, 3, 4, 5, 6, 7...
'Write file
System.IO.File.WriteAllBytes(filename, outBytes)
'Read file and hex output
Dim inBytes As Byte() = System.IO.File.ReadAllBy...
For i As Integer = 1 To inBytes.Length
Console.WriteLine("{0} : {1:X}", i - 1, inBy...
Next
End Sub
End Module
** 実行結果 [#pefccbc5]
上記のサンプルコードを実行した時のキャプチャになります。
#ref(run.png)
以上、バイナリファイルをバイト配列にすべてを読み込む File...
#htmlinsert(windev-btm.html)
終了行:
#navi(../)
* バイナリファイルをバイト配列にすべてを読み込む [#f7d99a...
バイナリファイルをバイト配列にすべてを読み込むメソッド ''...
電文ファイルなど、バイト配列に展開し操作したい場合など便...
#contents
* 関連サイト [#p35daca7]
-[[Microsoft .NET | File.ReadAllBytes(String) メソッド>ht...
-[[Microsoft .NET | File.WriteAllBytes(String, Byte[]) メ...
#htmlinsert(windev-top.html)
* 関連記事 [#o2425495]
-[[バイナリーファイルの作成・リード・ライト(バイト単位の...
* 動作確認環境 [#kcddeddc]
-Windows 10 ver.1909
-Visual Studio 2019
-.NET Core
-コンソールアプリケーション
* File.readallbytesサンプルコード [#k4ec2744]
本サンプルコードでは、 File.WriteAllBytes メソッドを使っ...
File.readallbytes メソッドで File.WriteAllBytes メソッド...
作成するファイルは、デスクトップに出力されます。
+ File.WriteAllBytes でファイルを作成し書き込み。
+ File.ReadAllBytes で 作成したファイルを読み込み、値を16...
** C# [#acaf2e56]
#ref(Program.cs)
using System;
class Program
{
static void Main(string[] args)
{
// Desktop path
string desktopPath = System.Environment.GetFolde...
// Read and Write filename
var filename = System.IO.Path.Combine(desktopPat...
// Output byte data
byte[] outBytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9...
// Write file
System.IO.File.WriteAllBytes(filename, outBytes);
// Read file and hex output
byte[] inBytes = System.IO.File.ReadAllBytes(fil...
for (int i = 1; i <= inBytes.Length; i++)
{
Console.WriteLine("{0} : {1:X}", i - 1, inBy...
}
}
}
** Visual Basic [#e6236899]
#ref(Program.vb)
Imports System
Module Program
Sub Main(args As String())
'Desktop path
Dim desktopPath As String = System.Environment.G...
'Read and Write filename
Dim filename = System.IO.Path.Combine(desktopPat...
'Output byte data
Dim outBytes As Byte() = {0, 1, 2, 3, 4, 5, 6, 7...
'Write file
System.IO.File.WriteAllBytes(filename, outBytes)
'Read file and hex output
Dim inBytes As Byte() = System.IO.File.ReadAllBy...
For i As Integer = 1 To inBytes.Length
Console.WriteLine("{0} : {1:X}", i - 1, inBy...
Next
End Sub
End Module
** 実行結果 [#pefccbc5]
上記のサンプルコードを実行した時のキャプチャになります。
#ref(run.png)
以上、バイナリファイルをバイト配列にすべてを読み込む File...
#htmlinsert(windev-btm.html)
ページ名: