C# read file to bytes,File.ReadAllFiles,File.Open(),BinaryReader
- 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的更多相关文章
- 错误: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 ...
- (转)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 ...
- 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 ...
- IO:File类(java.io.File)
public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...
- 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人阅读 ...
- git “bad index file sha1 signature fatal: index file corrupt”错误
在执行commit或revert等操作时,提示“bad index file sha1 signature fatal: index file corrupt”错误,导致操作失败.这是由于git的in ...
- JAVA FILE or I/O学习 - File学习
public class FileKnow { public static void main(String[] args) { //构建file对象 ,参数表示文件所在的路径 File file = ...
- malformed or corrupted AST file。。。module file out of date'
今天打开了曾经用的一个项目,(曾经的程序是对的)弹出了两个红框 malformed or corrupted AST file...module file out of date'. 这种结构. 解决 ...
- 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 ...
- 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 ? ...
随机推荐
- Fortran文件读写--xdd
1.常规读写 program FileWriteRead implicit none open(unit=,file="F:\desktop\File.txt") !open(un ...
- 解析深度学习 语音识别实践 pdf下载
链接:https://pan.baidu.com/s/1jd8_2nbz6M9e20lI3JdVGA 密码:1ikc 我从别人那里买的!可以友情赞助资瓷!
- Java的证书:HTTPS与SSL
在取得connection的时候和正常浏览器访问一样,仍然会验证服务端的证书是否被信任(权威机构发行或者被权威机构签名):如果服务端证书不被信任,则默认的实现就会有问题,一般来说,java在访问ssl ...
- Jeewx-Boot 1.1 版本发布,基于SpringBoot的开源微信管家系统
项目介绍 JeewxBoot是一款基于SpringBoot的开源微信管家系统,采用SpringBoot2.1.3 + Mybatis + Velocity 框架技术.支持微信公众号.微信第三方平台(扫 ...
- 【前端】之CSS3基础知识
CSS3 私有化前缀 考虑到CSS3的兼容性问题,某些属性需要添加浏览器的私有化前缀 几种主流浏览器的私有化前缀如下: Chrome.Safari:-webkit- Firefox:-moz- IE: ...
- Chapter 05—Advanced data management(Part 2)
二. 控制流 statement:一个单独的R语句或者是一个复合的R语句: cond:条件表达式,为TRUE或FALSE: expr:数字或字符表达式: seq:数字或字符串的顺序. 1.循环语句:f ...
- python元类深入解析
元类 什么是元类 元类是类的类,是类的模板(就如对象的模板是类一样) 元类的实例为类,类的实例为对象 元类是用来产生类的 动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,是运行时动 ...
- 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 ...
- 基于webpack实现多html页面开发框架二 css打包、支持scss、文件分离
本节主要介绍webpack打包的时候CSS的处理方式 一.解决什么问题 1.CSS打包 2.CSS处理浏览器兼容 3.SASS支持 4.CSS分离成单独的文件 ...
- 转:org.apache.maven.archiver.MavenArchiver.getManifest错误
eclipse导入新的maven项目时,pom.xml第一行报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.mav ...