导航:首页 > 文件教程 > filestream读取文件

filestream读取文件

发布时间:2021-02-13 12:01:51

『壹』 C# FileStream读写文件(.txt)时候用excel操作此文件,写入数据线程会被终止

private void WriteIntoFile(object obj,string filename)
{
lock (o)
{
using (FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write))
{
byte[] bytData = rawSerialize(obj);
fs.Write(bytData, 0, bytData.Length);
fs.Close();
}
}
}
第一,尝试下释放fs?
第二,尝试下运行共版享写权?using (FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write,FileShare.Write))?

『贰』 C#FileStream循环读取大文件有什么好处

虽然是在 while 循环内实现读写,但不能说是循环读取(循环读取说的是读到尾后有从头读),而是分段读取
分段读取可以减少缓存空间的内存开销,合适的缓存空间可提高硬盘的寻道效率

『叁』 FileStream怎样获得文件相对路径

string strAppPath = Application.StartupPath; //获得可来执行文件的自路径。

string strConfigPath = strAppPath + "\\Config\\DBConfig.ini"; //自己调整一下相对路径。

『肆』 C#用FileStream类文件读出指定txt文件内容时,怎么前面多了“”从哪儿来的

应该是编码问题, 请以默认编码格式读取文本内容

『伍』 C#,怎样利用filestream流查询文件中的某几个字

private string SelectStr(string str)
{
FileStream fs = new FileStream("d:\\a.txt", FileMode.Open);
StreamReader m_streamReader = new StreamReader(fs, System.Text.Encoding.GetEncoding("GB2312"));
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine();
do
{
if (strLine.Contains(str))
{
return strLine.Substring(strLine.IndexOf(str) - 4, 4);
}
strLine = m_streamReader.ReadLine();
} while (strLine != null && strLine != "");
m_streamReader.Close();
m_streamReader.Dispose();
fs.Close();
fs.Dispose();
return "";
}
}

『陆』 C# 用filestream读取文本的问题

刚好前天写了一个类,送你了.
public enum ArchiveMode
{
store,
load,
}
public static string BytesToString(byte[] bs, int start, int bsLen)
{
string ss = Encoding.Unicode.GetString(bs, start, bsLen);
return ss;
}
public static void StringToBytes(string text, byte[] bs, out int bsLen)
{
bsLen = Encoding.Unicode.GetBytes(text, 0, text.Length, bs, 0);
}
public class Archive
{
FileStream m_fs = null;
ArchiveMode m_Mode;

public Archive(FileStream fs, ArchiveMode mode)
{
m_Mode = mode;
m_fs = fs;
}

public void Close()
{
m_fs = null;
}
public bool IsStore
{
get { return m_Mode == ArchiveMode.store; }
}
public bool IsLoad
{
get { return m_Mode == ArchiveMode.load; }
}

public DateTime ReadDataTime()
{
if (IsStore)
throw new Exception("store模式下不允许读取");

byte[] bs8 = new byte[8];
m_fs.Read(bs8, 0, 8);
long l = System.BitConverter.ToInt64(bs8, 0);
DateTime dt = new DateTime(l);

return dt;
}
public void WriteDataTime(DateTime dt)
{
if (IsLoad)
throw new Exception("load模式下不允许写入");

byte[] bs = System.BitConverter.GetBytes(dt.ToBinary());
m_fs.Write(bs, 0, 8);
}
public int ReadCount()
{
if (IsStore)
throw new Exception("store模式下不允许读取");

byte[] bs = new byte[4];

m_fs.Read(bs, 0, 4);
return System.BitConverter.ToInt32(bs, 0);

}
public void WriteCount(int n)
{
if (IsLoad)
throw new Exception("load模式下不允许写入");
byte[] bs = System.BitConverter.GetBytes(n);
//if (n > 0xFFFF)
//{
// m_fs.Write(System.BitConverter.GetBytes(0xFFFF), 0, 2);
//}
m_fs.Write(bs, 0, bs.Length);
}
public long ReadLong()
{
if (IsStore)
throw new Exception("store模式下不允许读取");

byte[] bs = new byte[8];

m_fs.Read(bs, 0, 8);
return System.BitConverter.ToInt64(bs, 0);

}
public void WriteLong(long n)
{
if (IsLoad)
throw new Exception("load模式下不允许写入");
byte[] bs = System.BitConverter.GetBytes(n);

m_fs.Write(bs, 0, bs.Length);
}
public int Read(byte[] bs, int count)
{
if (IsStore)
throw new Exception("store模式下不允许读取");
return m_fs.Read(bs, 0, count);
}
public void Write(byte[] bs, int count)
{
if (IsLoad)
throw new Exception("load模式下不允许写入");
m_fs.Write(bs, 0, count);
}
public void WriteString(string text)
{
int len = text.Length * 2;
byte[] bs = new byte[len + 8];
int oulen = 0;
F.StringToBytes(text, bs, out oulen);

WriteCount(oulen);
Write(bs, oulen);
}

public string ReadString()
{
int len = ReadCount();
byte[] bs = new byte[len];
Read(bs, len);

return F.BytesToString(bs, 0, len);
}
}

『柒』 asp.net filestream 如何读取pdf文件,这个该怎么做

<%@ Page Language="C#"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>

<%

Response.Clear();
string path = @"F:\TDDOWNLOAD\Book\C#游戏编程入门.pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disponstion", "filename=C#游戏编程入门.pdf");

byte[] buffer = new byte[256];

FileStream fs = File.Open(path, FileMode.Open);
Response.AddHeader("content-length", fs.Length.ToString());
int length = (int)fs.Length;

if (Response.IsClientConnected)
{
while (length > -1)
{
length = length - buffer.Length;
fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, buffer.Length);
}

}
fs.Close();
Response.End();

%>
是哦 这个就是显示到网页上的。

『捌』 C#怎么用FileStream一行一行的读取文本

FileStream fs = New FileStream (文件路来径, FileMode.Open);
StreamReader streamReader = new StreamReader(fileStream);
string line = "";
while ((line = streamReader.ReadLine()) !源= null)
{
//line就是一行一行的文本
。。。
}

阅读全文

与filestream读取文件相关的资料

热点内容
网络中常用的传输介质 浏览:518
文件如何使用 浏览:322
同步推密码找回 浏览:865
乐高怎么才能用电脑编程序 浏览:65
本机qq文件为什么找不到 浏览:264
安卓qq空间免升级 浏览:490
linux如何删除模块驱动程序 浏览:193
at89c51c程序 浏览:329
怎么创建word大纲文件 浏览:622
袅袅朗诵文件生成器 浏览:626
1054件文件是多少gb 浏览:371
高州禁养区内能养猪多少头的文件 浏览:927
win8ico文件 浏览:949
仁和数控怎么编程 浏览:381
项目文件夹图片 浏览:87
怎么在东芝电视安装app 浏览:954
plc显示数字怎么编程 浏览:439
如何辨别假网站 浏览:711
宽带用别人的账号密码 浏览:556
新app如何占有市场 浏览:42

友情链接