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 ? ...
随机推荐
- 容器镜像服务联手 IDE 插件,实现一键部署、持续集成与交付
容器技术提供了一种标准化的交付方式,将应用的代码以及代码环境依赖都打包在一起,成为一个与环境无关的交付物,可以被用在软件生命周期的任何阶段,彻底改变了传统的软件交付方式. 甚至可以说,是在容器技术之后 ...
- Tomcat安装和使用
1.Tomcat简介 Tomcat是Apache开源组织下的开源免费的中小型Web应用服务器,支持javaEE中的servlet和jsp规范. 2.Windows版安装和使用 下载地址:http:// ...
- setBounds方法,与setLayout(null)
首先把相关容器的布局方式设为 setLayout(null); 然后调用组件的 setBounds() 方法 设置button的位置为(100,100) 长宽分别为 60,25 jButton.se ...
- java引用知识
最近从新拜读<深入理解Java虚拟机:JVM高级特性与最佳实践>这本书,看到有关引用的相关知识,以前没有好的习惯,这次看完在博客上记录下 引用:如果reference类型中的数据存储的数值 ...
- Redis的面试问题总结,面试跳槽必备
1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库 ...
- NIO-概览
目录 NIO-概览 目录 前言 什么是NIO 通道 缓冲区 选择器 其他 管道 FileLock 参考文档 NIO-概览 目录 NIO-概览 前言 本来是想学习Netty的,但是Netty是一个NIO ...
- django框架简介及自定义简易版框架
web应用与web框架本质 概念 什么是web应用程序呢? Web应用程序就一种可以通过互联网来访问资源的应用程序, 用户可以只需要用一个浏览器而不需要安装其他程序就可以访问自己需要的资源. 应用软件 ...
- react修改端口
react修改端口 在react官网根据文档安装好项目之后,发现新项目没有了scripst文件夹 之前版本是在scripts文件夹中的starts.js中修改 新版本修改port发现移入到了依赖里面 ...
- pom父工程dependencyManagement中的jar包在子工程中不写版本号无法引入的问题
1.遇到的问题: 本人用的idea,然后在导入别人的项目的时候,pom文件中没有报错了,但是在maven栏目中jar包却一直报红,是因为我没写版本的原因吗?不对呀,我的父工程下已经写了springb ...
- Python-Excel 模块哪家强 #华为云·寻找黑马程序员#
python操作excel 最原始的莫过于两位老牌黄金搭档xlrd xlwt了,针对二者的封装有如下模块: xlutils & xlrd & xlwt 为什么把这三个一起说? 首先,x ...