c#简单读取文本的实例方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace StreamReadWrite
{
class Program
{
static void Main(string[] args)
{
// Get the directories currently on the C drive.
DirectoryInfo[] cDirs = new DirectoryInfo(@"e:\").GetDirectories();
// Write each directory name to a file.
using (StreamWriter sw = new StreamWriter("CDriveDirs.txt"))
{
foreach (DirectoryInfo dir in cDirs)
{
sw.WriteLine(dir.Name);
}
}
// Read and show each line from the file.
string line = "";
using (StreamReader sr = new StreamReader("CDriveDirs.txt"))
{
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
}
}
相关推荐
-
c# 以二进制读取文本文件
复制代码 代码如下: using System; using System.IO; public class FileApp { public static void Main() { // 在当前目录创建一个文件myfile.txt,对该文件具有读写权限 FileStream fsMyfile = new FileStream("myfile.txt" , FileMode.Create, FileAccess.ReadWrite);
-
C# 创建文本文件写入读取实现代码
第一次运行时: 第二次运行时: 复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace 文件操作 { class Program { static void Main(string[] args) { //创建一个文本文件,最好先判断一下 StreamWriter sw; if (!File.Exists(
-
c#简单读取文本的实例方法
复制代码 代码如下: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO; namespace StreamReadWrite{ class Program { static void Main(string[] args) { // Get the directories currently
-
使用Python读写文本文件及编写简单的文本编辑器
学习raw_input和argv是学习读取文件的前提,你可能不能完全理解这个练习,所以认真学习并检查.如果不认真的话,很容易删除一些有用的文件. 这个练习包含两个文件,一个是运行文件ex15.py,一个是ex15_sample.txt.第二个文件不是脚本文件,只包括一些文本,如下: This is stuff I typed into a file. It is really cool stuff. Lots and lots of fun to have in here. 我们要做的就是打开这
-
python读取文本中数据并转化为DataFrame的实例
在技术问答中看到一个这样的问题,感觉相对比较常见,就单开一篇文章写下来. 从纯文本格式文件 "file_in"中读取数据,格式如下: 需要输出成"file_out",格式如下: 数据的原格式是"类别:内容",以空行"\n"为分条目,转换后变成一个条目一行,按照类别顺序依次写出内容. 建议读取后,使用pandas,把数据建立称DataFrame的表格.这样方便以后处理数据.但是原格式并不是通常的表格格式,所以要先做一些简单的处理
-
Python实现简单的文本相似度分析操作详解
本文实例讲述了Python实现简单的文本相似度分析操作.分享给大家供大家参考,具体如下: 学习目标: 1.利用gensim包分析文档相似度 2.使用jieba进行中文分词 3.了解TF-IDF模型 环境: Python 3.6.0 |Anaconda 4.3.1 (64-bit) 工具: jupyter notebook 注:为了简化问题,本文没有剔除停用词"stop-word".实际应用中应该要剔除停用词. 首先引入分词API库jieba.文本相似度库gensim import ji
-
从python读取sql的实例方法
从python读取sql的方法: 1.利用python内置的open函数读入sql文件: 2.利用第三方库pymysql中的connect函数连接mysql服务器: 3.利用第三方库pandas中的read_sql方法读取传入的sql文件即可. python 直接读取 sql 文件,达到使用 read_sql 可执行的目的 # sql文件夹路径 sql_path = 'sql文件夹路径' + '\\' # sql文件名, .sql后缀的 sql_file = 'sql文件名.sql' # 读取
-
java简单读取properties配置文件的方法示例
本文实例讲述了java简单读取properties配置文件的方法.分享给大家供大家参考,具体如下: 读取配置文件,小结如下 import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; public class loadConf { private Properties prop = new Properties(); private void loadconf() t
-
Python简单检测文本类型的2种方法【基于文件头及cchardet库】
本文实例讲述了Python简单检测文本类型的方法.分享给大家供大家参考,具体如下: 1.根据文件头. #是否为带BOM头的UTF8文件 def IsUtf8BomFile(pathfile): if b'\xef\xbb\xbf' == open(pathfile, mode='rb').read(3)): return True return False 2.用cchardet库. >>> import cchardet >>> cchardet.detect(ope
-
python简单读取大文件的方法
本文实例讲述了python简单读取大文件的方法.分享给大家供大家参考,具体如下: Python读取大文件(GB级别)采用的办法很简单: with open(...) as f: for line in f: <do something with line> 例如: with open(filepath,'r') as infile: for line in infile: print line 一切都交给python解释器处理,读取效率很高,且占用资源少. stackoverflow参考链接:
-
PHPExcel简单读取excel文件示例
本文实例讲述了PHPExcel简单读取excel文件的方法.分享给大家供大家参考,具体如下: PHP Excel 2007 classes Project providing a set of classes for the PHP programming language, which allow you to write to and read from different file formats, like Excel 2007, PDF, HTML, ... This project
-
php简单读取.vcf格式文件的方法示例
本文实例讲述了php简单读取.vcf格式文件的方法.分享给大家供大家参考,具体如下: /** * 读取.vcf格式文件 * @param $filename */ function readCvf($filename){ $file = fopen($filename,"r"); while(! feof($file)) { $line=fgets($file); $encoding = mb_detect_encoding($line, array('GB2312','GBK','U
随机推荐
- 解析oracle对select加锁的方法以及锁的查询
- Java计算一个数加上100是完全平方数,加上168还是完全平方数
- IOS安装CocoaPods详细教程
- Ruby和Ruby on Rails中解析JSON格式数据的实例教程
- ASP.NET微信开发(接口指南)
- ASP.net中实现基于UrlRewrite的防盗链功能
- asp.net 服务器控件的 ID,ClientID,UniqueID 的区别
- Android控件之ListView用法实例详解
- php中使用session_set_save_handler()函数把session保存到MySQL数据库实例
- 正则表达式中不区分大小写的写法
- Android基于CountDownView的时间控件扩展
- JavaScript中的console.log()函数详细介绍
- 通用javascript脚本函数库 方便开发
- php中随机显示图片的函数代码
- mongodb数据库的6个安全设置命令
- 浅析jquery与checkbox的checked属性的问题
- 适用于php-5.2 的 php.ini 中文版[金步国翻译]
- c语言_构建一个静态二叉树实现方法
- Android数据加密之Des加密详解
- android开发教程之清除android数据缓存示例(清除本地数据缓存)