1. using System;
  2. using System.Text;
  3. using System.IO;
  4.  
  5. namespace ConsoleApplication15
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string fileName = @"..\..\Images\lj.jpg";
  12. FileStreamReadToBytes(fileName);
  13. ReadFileToBinaryBytes(fileName);
  14. FileReadAllBytesDemo(fileName);
  15. Console.ReadLine();
  16. }
  17.  
  18. static void FileStreamReadToBytes(string fileName)
  19. {
  20. if(!File.Exists(fileName))
  21. {
  22. return;
  23. }
  24.  
  25. byte[] bytesArr = null;
  26. using (FileStream fs = new FileStream(fileName, FileMode.Open))
  27. {
  28. bytesArr = new byte[fs.Length];
  29. fs.Write(bytesArr, , bytesArr.Length);
  30. Console.WriteLine(bytesArr.Length);
  31. }
  32. }
  33.  
  34. static void FileReadAllBytesDemo(string fileName)
  35. {
  36. byte[] readBytes = System.IO.File.ReadAllBytes(fileName);
  37. Console.WriteLine(readBytes.Length);
  38. }
  39.  
  40. static void ReadFileToBinaryBytes(string fileName)
  41. {
  42. if (!File.Exists(fileName))
  43. {
  44. return;
  45. }
  46.  
  47. byte[] bytesArr = null;
  48. using (FileStream fs = new FileStream(fileName, FileMode.Open))
  49. {
  50. using (BinaryReader binReader = new BinaryReader(fs,Encoding.UTF8))
  51. {
  52. bytesArr = binReader.ReadBytes((int)fs.Length);
  53. Console.WriteLine(bytesArr.Length);
  54. }
  55. }
  56. }
  57. }
  58. }

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. Fortran文件读写--xdd

    1.常规读写 program FileWriteRead implicit none open(unit=,file="F:\desktop\File.txt") !open(un ...

  2. 解析深度学习 语音识别实践 pdf下载

    链接:https://pan.baidu.com/s/1jd8_2nbz6M9e20lI3JdVGA  密码:1ikc 我从别人那里买的!可以友情赞助资瓷!

  3. Java的证书:HTTPS与SSL

    在取得connection的时候和正常浏览器访问一样,仍然会验证服务端的证书是否被信任(权威机构发行或者被权威机构签名):如果服务端证书不被信任,则默认的实现就会有问题,一般来说,java在访问ssl ...

  4. Jeewx-Boot 1.1 版本发布,基于SpringBoot的开源微信管家系统

    项目介绍 JeewxBoot是一款基于SpringBoot的开源微信管家系统,采用SpringBoot2.1.3 + Mybatis + Velocity 框架技术.支持微信公众号.微信第三方平台(扫 ...

  5. 【前端】之CSS3基础知识

    CSS3 私有化前缀 考虑到CSS3的兼容性问题,某些属性需要添加浏览器的私有化前缀 几种主流浏览器的私有化前缀如下: Chrome.Safari:-webkit- Firefox:-moz- IE: ...

  6. Chapter 05—Advanced data management(Part 2)

    二. 控制流 statement:一个单独的R语句或者是一个复合的R语句: cond:条件表达式,为TRUE或FALSE: expr:数字或字符表达式: seq:数字或字符串的顺序. 1.循环语句:f ...

  7. python元类深入解析

    元类 什么是元类 元类是类的类,是类的模板(就如对象的模板是类一样) 元类的实例为类,类的实例为对象 元类是用来产生类的 动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,是运行时动 ...

  8. iptables规则备份和恢复、firewalld的9个zone、以及firewalld关于zone和service的操作 使用介绍

    第7周第5次课(5月11日) 课程内容: 10.19 iptables规则备份和恢复10.20 firewalld的9个zone10.21 firewalld关于zone的操作10.22 firewa ...

  9. 基于webpack实现多html页面开发框架二 css打包、支持scss、文件分离

    本节主要介绍webpack打包的时候CSS的处理方式 一.解决什么问题      1.CSS打包      2.CSS处理浏览器兼容      3.SASS支持      4.CSS分离成单独的文件 ...

  10. 转:org.apache.maven.archiver.MavenArchiver.getManifest错误

    eclipse导入新的maven项目时,pom.xml第一行报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.mav ...