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 ? ...
随机推荐
- day29 文件的上传和下载 socketserver(并发)
文件上传的讲解: import subprocess res=subprocess.Popen("dir", shell=True, stderr=subprocess.PIPE, ...
- 题解 P1226 【【模板】快速幂||取余运算】
1.题目分析 原题 本题在于快速幂的使用,以及对long long的应用问题. 2.解题思路 快速幂 求幂常见用法: int pow(int a,int b) { int ans; for(int i ...
- Unicode和Ascii的区别
计算机只能处理数字,如果要处理文本,就必须把文本转换成数字. 最早的计算机设计采用8bit作为一个字节,所以,一个字节只能表示的最大整数255. 0-255被用来表示数字和一些符号,这个编码 ...
- 【Android - 控件】之MD - TextInputLayout的使用
TextInputLayout是Android 5.0新特性——Material Design中的一个布局控件,主要用来嵌套EditText,实现数据输入时的一些效果,如: 当输入框获取焦点时,输入提 ...
- Coroutines in Android - One Shot and Multiple Values
Coroutines in Android - One Shot and Multiple Values 在Android中, 我们用到的数据有可能是一次性的, 也有可能是需要多个值的. 本文介绍An ...
- MyEclispe启动Tomcat7时出现错误The servlets named [LoginServlet] and [com.liu.control.LoginServlet] are both
刚开始尝试写Servlet代码,第一天就碰到这个错误,在网上找了很多资料才找到解决办法,在此记录一下. org.apache.catalina.LifecycleException: Failed t ...
- 基于Quartz.NET框架的任务计划管理工具
最近接到一个小需求 ——可以定期同步20个Sql Server 7.0数据库里的数据(数据量会预计>10000),并保存为CSV格式文件 ——可以设置保存文件数据量 ——该应用需要用WinFor ...
- 企业日常巡检shell脚本
Linux内部查看系统信息 $INTERNET192忽略 [root@ mysql-master ~]# ip a|grep eth0|grep inet|cut -d' ' -f6|cut -d'/ ...
- ThinkPHP5——模型关联(多对多关联)
关联定义 多对多关联不像一对一和一对多关联,它还要多建一个中间表用来处理多对多的关联,例如: #城市 create table city ( c_id int primary key AUTO_INC ...
- 双显卡安装Ubuntu 18.04和NVIDIA驱动
踩坑笔记: 用软碟通制作UBUNTU18.04 LTS启动盘 长按DEL键进入BIOS,关闭Security Boot,设置USB优先启动 在黑白的grub引导界面(第一行是Try Ubuntu- 第 ...