using System;
using System.IO;
using System.Text;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
ReadAFileConvertToArray();
}
private static void ReadAFileConvertToArray()
{
string basePath = @"C:\Users\admin\Desktop\files\";
string rel1 = @"pdf.pdf";
string rel2 = @"xml.xml";
string rel3 = @"doc.doc";
string rel4 = @"txt.txt";
string rel5 = @"csv.csv";
string rel6 = @"xls.xls";
FileInfo fileInfo = new FileInfo(basePath + rel5);
byte[] file;
using (var stream = new FileStream(basePath+ rel5, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
var fileExtension = fileInfo.Extension;
var fileLength = fileInfo.Length;
var fileContent = Encoding.UTF8.GetString(file, 0, file.Length);
var file2 = BitConverter.ToString(file);
Console.WriteLine(fileContent);
//File.WriteAllBytes(@"C:\Users\admin\Desktop\files\1\Foo.xml", file);
Console.ReadLine();
// byte[] file = fileToPut.ToArray();
}
}
}
No comments:
Post a Comment