C# File类,文件读取,编码
来源:互联网 发布:数据库管理范式 编辑:程序博客网 时间:2024/06/13 18:18
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace _14File类的操作{ class Program { static void Main(string[] args) { //File 静态类 //Exist():判断指定的文件是否存在 //Create():创建 //Move():剪切 //Copy():复制 //Delete():删除 //if (!File.Exists("1.txt")) //{ // File.Create("1.txt"); //} //if (File.Exists("1.txt")) //{ // File.Delete("1.txt"); //} // //File.Copy(@"C:\Users\SpringRain\Desktop\english.txt", @"D:\aaaaaa.txt"); //Console.WriteLine("操作成功"); //File.Move(@"D:\aaaaaa.txt", @"C:\Users\SpringRain\Desktop\bbbbbb.txt"); //ReadAllLines()默认采用的编码格式是utf-8 //string[] str = File.ReadAllLines(@"C:\Users\SpringRain\Desktop\english.txt"); //ReadAllText()默认采用的编码格式也是utf-8 //string str = File.ReadAllText(@"C:\Users\SpringRain\Desktop\english.txt"); //Console.WriteLine(str); //byte[] buffer = File.ReadAllBytes(@"C:\Users\SpringRain\Desktop\english.txt"); ////字节数组---->字符串 //string str = Encoding.UTF8.GetString(buffer); //Console.WriteLine(str); //string str="张三李四王五百家姓"; ////字符串--->字节数组 //byte[] buffer= Encoding.Default.GetBytes(str); //File.WriteAllBytes(@"C:\Users\SpringRain\Desktop\121212.txt", buffer); //Console.WriteLine("写入成功"); //Console.ReadKey(); //File.WriteAllLines(@"C:\Users\SpringRain\Desktop\121212.txt", new string[] { "a", "b" }); //File.WriteAllText(@"C:\Users\SpringRain\Desktop\121212.txt", "c"); //byte[] buffer = new byte[3]; //Console.WriteLine(buffer.ToString()); //字节数组---->所在的命名空间,ToString使用较少,MD5使用ToString() //18 99 221 我爱你 //Encoding.Default.GetString(); //字节数组---->字符串 } }}
阅读全文
0 0
- C# File类,文件读取,编码
- File类 读取文件
- File类3 文件读取
- C#控制台基础 file与filestream读取文件的区别
- 多线程读取文件File
- java File读取文件
- File 读取文件
- 按文件编码读取
- 读取文件编码
- C#使用StreamReader类读取文件文件
- C#中File类的文件操作方法
- C# file 文件操作
- C# file文件操作
- file 读取写入文件 HTML
- java File文件读取大全
- input file 读取文件内容
- 文件读取CFile、File、getline
- File.io读取文件(一)
- windows文本文件 utf-8 无bom格式编码引发的惨案(maven resource 替换失败)...mark
- 设计模式-建造者模式
- #ifdef #else #endif #fi #ifndef 的用法(高手勿进)
- java学习笔记一--classpath设置
- 中北大学NUC2017新生赛1008/NOJ-1988
- C# File类,文件读取,编码
- C#总结
- 表单传输后台乱码-get/post区别
- Java总结5_6
- 前言-Java编程
- Attention Is All You Need
- angular4系列之ViewEncapsulation
- cpp: 使用typedef定义函数指针
- 事务操作暨mybatis的事务操作