社区
C#
帖子详情
怎样将一个.txt文件读入到string 变量中
borwin
2004-11-10 11:28:30
怎样将一个.txt文件读入到string 变量中
...全文
172
4
打赏
收藏
怎样将一个.txt文件读入到string 变量中
怎样将一个.txt文件读入到string 变量中
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
龍过鸡年
2004-11-10
打赏
举报
回复
string content = ""; // 定义字符串
//定义文件读取对象
using(StreamReader reader = new StreamReader(fileName, System.Text.Encoding.Default))
{
content = reader.ReadToEnd(); //读取文件内容
reader.Close(); //关闭文件
}
egxsun
2004-11-10
打赏
举报
回复
字符串长度有限制吧?超过64k是不是就不行了?
wl246
2004-11-10
打赏
举报
回复
sequelbo(那一剑的风情)方法很好,比较简单
sequelbo
2004-11-10
打赏
举报
回复
private string getstring(string path)
{
System.IO.FileStream fs = System.IO.File.OpenRead(path);
byte[] file = new Byte[fs.Length];
fs.Read(file,0,Convert.ToInt32(fs.Length));
string s = System.Text.Encoding.Default.GetString(file,0,file.Length);
fs.Close();
return s;
}
C#把整个
文件
内容
读入
字符串
变量
的方法
本文实例讲述了C#把整个
文件
内容
读入
字符串
变量
的方法。分享给大家供大家参考。具体实现方法如下: using System; namespace PlayingAround { class ReadAll { public static void Main(
string
[] args) {
string
...
C++ 读
文件
将
文件
内容
读入
到字符串
string
中
#include #include #include #include #include using namespace std; //从
文件
读入
到
string
里
string
readFileInto
String
(char * filename) ...//将
文件
读入
到o
string
stream对象buf
中
o
string
stre
Python数据挖掘与分析速成班
Python数据挖掘与分析快速入门,本课程介绍使用Python进行数据分析的第一步,即不同类型的数据获取,内容涉及
txt
、csv、docx、xlsx、json等不同类型
文件
内容的读取,列表、字典、集合等在数据分析时常用的Python内置...
C++ 读
文件
将
文件
内容
读入
到字符串
string
中
的方法
#include <
string
> #include <fstream> #include <sstream> #include <iostream>...//从
文件
读入
到
string
里
string
readFileInto
String
(char * filename) ...//将
文件
读入
到o
string
stream对
从键盘
读入
一行字符,写到
文件
output.
txt
文件
中
(字节流)
(仅适用于英文字符串,
中
文字符将出现乱码,应使用字符流) /* * 从键盘
读入
一行字符,写到
文件
output.
txt
文件
中
*/ import java.io. *; public class MyFileOutput { public static void main(
String
[] argv) { ...
C#
110,534
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章