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. Xamarin.Forms学习系列之Android集成极光推送

    一般App都会有消息推送的功能,如果是原生安卓或者IOS集成消息推送很容易,各大推送平台都有相关的Sample,但是关于Xamarin.Forms的消息推送集成的资料非常少,下面就说下Xamarin. ...

  2. python模块成像库pillow

    python之成像库pillow python提供了python image library图像库,处理图像功能,该库提供了广泛的文件格式支持,如JPEG.PNG.GIF.等,它提供了图像档案.图像显 ...

  3. 深入理解inode和硬链接和软连接和挂载点

    inode 一.inode是什么? 理解inode,要从文件储存说起. 扇区 文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector).每个扇区储存512字节(相当于0.5 ...

  4. Bean中要使用配置文件中的值,使用set方法注入

    /** * Sensors Analytics Bean * @author Feng */ @Component public class SensorsAnalyticsBean { /*** * ...

  5. shell配置mysql主从

    Environment:CentOS7两台主机 一台做主机,一台做备份机 注意: 首先第一步关闭两台机器的防火墙 主机shell操作: #!/bin/bash slave_user='zjt' sla ...

  6. 第九次作业——DFA最小化,语法分析初步

    老师:MissDu 提交作业 1.将DFA最小化:教材P65 第9题 答: 2.构造以下文法相应的最小的DFA S→ 0A|1B A→ 1S|1 B→0S|0 3.自上而下语法分析,回溯产生的原因是 ...

  7. CentOS 7 安装并配置 MySQL 5.7

    Linux使用MySQL Yum存储库上安装MySQL 5.7,适用于Oracle Linux,Red Hat Enterprise Linux和CentOS系统. 1.添加MySQL Yum存储库 ...

  8. UIScrollView,UICollectionView 和UITableView的属性和方法

    UIScrollView,UICollectionView 和UITableView 三者之间的关系:UIScrollView是 UICollectionView 和 UITableView 的父类. ...

  9. jQuery中的基本的选择器学习(补充版)

    先看整体代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  10. [TimLinux] Python 再谈装饰器

    参考链接:https://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators 1. 函数对象 能 ...