using System;
using System.Text;
using System.IO; namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
string fileName = @"..\..\Images\lj.jpg";
FileStreamReadToBytes(fileName);
ReadFileToBinaryBytes(fileName);
FileReadAllBytesDemo(fileName);
Console.ReadLine();
} static void FileStreamReadToBytes(string fileName)
{
if(!File.Exists(fileName))
{
return;
} byte[] bytesArr = null;
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
bytesArr = new byte[fs.Length];
fs.Write(bytesArr, , bytesArr.Length);
Console.WriteLine(bytesArr.Length);
}
} static void FileReadAllBytesDemo(string fileName)
{
byte[] readBytes = System.IO.File.ReadAllBytes(fileName);
Console.WriteLine(readBytes.Length);
} static void ReadFileToBinaryBytes(string fileName)
{
if (!File.Exists(fileName))
{
return;
} byte[] bytesArr = null;
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
using (BinaryReader binReader = new BinaryReader(fs,Encoding.UTF8))
{
bytesArr = binReader.ReadBytes((int)fs.Length);
Console.WriteLine(bytesArr.Length);
}
}
}
}
}

C# read file to bytes,File.ReadAllFiles,File.Open(),BinaryReader的更多相关文章

  1. 错误:android.view.InflateException: Binary XML file line #167: Binary XML file line #167: Error inflating class <unknown>

    1:错误日志 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.8.activity.RecordActiv ...

  2. (转)win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

    原文地址:http://www.cnblogs.com/fnng/p/4115607.html 作者:虫师 今天想在在win7 64位环境下使用python 操作mysql 在安装MySQL-pyth ...

  3. win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

    今天想在在win7 64位环境下使用python 操作mysql 在安装MySQL-python 时报错: _mysql.c _mysql.c(42) : fatal error C1083: Can ...

  4. IO:File类(java.io.File)

    public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...

  5. error BK1506 : cannot open file '.\Debug\????????.sbr': No such file or dire

    http://blog.csdn.net/shuilan0066/article/details/8738035 分类:            调试错误信息2013-03-29 19:08492人阅读 ...

  6. git “bad index file sha1 signature fatal: index file corrupt”错误

    在执行commit或revert等操作时,提示“bad index file sha1 signature fatal: index file corrupt”错误,导致操作失败.这是由于git的in ...

  7. JAVA FILE or I/O学习 - File学习

    public class FileKnow { public static void main(String[] args) { //构建file对象 ,参数表示文件所在的路径 File file = ...

  8. malformed or corrupted AST file。。。module file out of date&#39;

    今天打开了曾经用的一个项目,(曾经的程序是对的)弹出了两个红框 malformed or corrupted AST file...module file out of date'. 这种结构. 解决 ...

  9. adb pull 报错处理:adb: error: cannot create file/directory 'E:\': No such file or directory

    adb pull /sdcard/1.txt e:/ 报错:adb: error: cannot create file/directory 'E:\': No such file or direct ...

  10. failed to create pid file /var/run/rsyncd.pid: File exists报错

    [root@pcidata-jenkins ansible_playbooks]# ps aux|grep rsyncroot      1799  0.0  0.0 114652   480 ?   ...

随机推荐

  1. 【Luogu P1168】【Luogu P1801&UVA 501】中位数&黑匣子(Black Box)——对顶堆相关

    Luogu P1168 Luogu P1801 UVA 501(洛谷Remote Judge) 前置知识:堆.优先队列STL的使用 对顶堆 是一种在线维护第\(k\)小的算法. 其实就是开两个堆,一个 ...

  2. YoungLots Team - Record a software installation

    一.写在最前 本文记录安装或配置以下软件或环境的过程:VScode,Xampp,navicat,PHP,html,CSS,SQL,JavaScript. 作者使用的环境:浏览器:Google Chro ...

  3. java静态初始化块(静态域)

    1. 类变量的初始化可通过静态初始化块来进行. 代码放在一对大括号内,大括号前用static修饰:static {……} 一个类可定义1个或多个静态初始化块. 静态初始化块会在加载时调用而且只被调用一 ...

  4. Java基础部分(11~20)

    11."=="和 equals 方法究竟有什么区别? (单独把一个东西说清楚,然后再说清楚另一个,这样,它们的区别自然就出来了,混在一起说,则很难说清楚) ==操作符专门用来比较两 ...

  5. Python小数据保存,有多少中分类?不妨看看他们的类比与推荐方案...

    小数据存储 我们在编写代码的时候,经常会涉及到数据存储的情况,如果是爬虫得到的大数据,我们会选择使用数据库,或者excel存储.但如果只是一些小数据,或者说关联性较强且存在存储后复用的数据,我们该如何 ...

  6. 洛谷 题解 P4613 【[COCI2017-2018#5] Olivander】

    我又双叒叕被包菜辣! P4613 [COCI2017-2018#5] Olivander 首先,不知道为什么这题无法提交翻译: 所以,我先放个翻译: 哈利波特在与伏地魔的战斗中损坏了他的魔杖.他决定在 ...

  7. SpringBoot添加热部署

    一.导入依赖 <!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> & ...

  8. 使用Carthage集成Alamofire

    Carthage相较于Cocoapods有着使用灵活,对目标工程改动小的优势,使得它越来越受欢迎.今天就对我使用Carthage集成FBSDK做一个记录. 1.首先https://github.com ...

  9. Java学习笔记(面向对象下)

    面向对象(下) 类的继承 类的继承是指在一个现有类的基础上去构建一个新的类,构建出来的新类称为子类,现有类称为父类,子类会自动拥有父类所有可继承的属性和方法.(用extends关键字)   //定义A ...

  10. 2018HDU多校训练-3-Problem M. Walking Plan

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan  Problem Description There are n inte ...