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. 新闻实时分析系统-inux环境准备与设置

    1.Linux系统常规设置 1)设置ip地址 项目视频里面直接使用界面修改ip比较方便,如果Linux没有安装操作界面,需要使用命令:vi /etc/sysconfig/network-scripts ...

  2. 【Luogu P1164】小A点菜

    题目原链接: Luogu 小A点菜 [解题思路] 常规的0-1背包,不过是求装满整个背包的方案数,只要把0-1背包的状态转移方程稍微改一下就行.因为要求方案数,那么把方程中的max换成sum就行. [ ...

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

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

  4. 实战webpack系列03

    03.Webpack的强大功能 一.生成Source Maps(使调试更容易) 通过简单的配置,webpack就可以在打包时为我们生成的source maps,这为我们提供了一种对应编译文件和源文件的 ...

  5. 【Android - 自定义View】之不同事件的处理

    在Android的自定义View中,往往需要处理一系列的事件,如触摸事件.双击事件.缩放事件等.本文将这些事件及其处理进行总结.本文将持续更新,将我在自定义View的实践中用到的事件及其处理进行总结. ...

  6. 教你如何提高 PHP 代码的质量

    说实话,在代码质量方面,PHP 的压力非常大.通过阅读本系列文章,您将了解如何提高 PHP 代码的质量. 我们可以将此归咎于许多原因,但这肯定不仅仅是因为 PHP 生态系统缺乏适当的测试工具.在本文中 ...

  7. 小白的springboot之路(五)、集成druid

    0-前言 Druid阿里巴巴开源的一个java数据库连接池,是Java语言中最好的数据库连接池,Druid能够提供强大的监控和扩展功能:集成它能够方便我们对数据库连接进行监控和分析,下面我们来集成它: ...

  8. Java修炼——String类_常用方法_常量池

    String类的定义:String 是不可变字符序列 String 类的常用方法(全部都是不能改变String本身的值,都是在常量池里输出,没有改变其值) String string="ab ...

  9. nitacm20317 来自张司机的挑战书

    题目:让你求从x到y中(1<=x<=y<=10^18),二进制一的个数最多的数是哪个,如果有多个相同的答案,输出最小的. 题目链接:https://www.nitacm.com/pr ...

  10. nbuoj2784 倒水

    题目:http://www.nbuoj.com/v8.83/Problems/Problem.php?pid=2784 一天,TJ买了N个容量无限大的瓶子,开始时每个瓶子里有1升水.接着TJ决定只保留 ...