C# Stream Copy .net流复制到另一个流
来源:互联网 发布:windows 8.1怎么激活 编辑:程序博客网 时间:2024/06/12 20:49
文章参考:http://www.jetwu.cn/archives/741
.net 4.5 中流复制的方法:Stream.CopyToAsync
1
2
3
public
Task CopyToAsync(
Stream destination
)
示例:
1
2
3
4
5
6
7
8
9
10
11
12
string
StartDirectory =
@"c:\Users\exampleuser\start"
;
string
EndDirectory =
@"c:\Users\exampleuser\end"
;
foreach
(
string
filename
in
Directory.EnumerateFiles(StartDirectory))
{
using
(FileStream SourceStream = File.Open(filename, FileMode.Open))
{
using
(FileStream DestinationStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf(
'\\'
))))
{
await SourceStream.CopyToAsync(DestinationStream);
}
}
}
.net 4.0 中流复制的方法:Stream.CopyTo
1
2
3
4
5
6
MemoryStream destination =
new
MemoryStream();
using
(FileStream source = File.Open(
@"c:\temp\data.dat"
,FileMode.Open))
{
source.CopyTo(destination);
}
.net 3.5及以下版本 流的复制 需要自己写代码实现
流复制方法一:
public static void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[32768]; long TempPos = input.Position; while (true) { int read = input.Read (buffer, 0, buffer.Length); if (read <= 0) break; output.Write (buffer, 0, read); } input.Position = TempPos;// or you make Position = 0 to set it at the start }
流复制方法二:
1
2
3
4
5
6
public
static
void
CopyStream(Stream input, Stream output){
using
(StreamReader reader =
new
StreamReader(input))
using
(StreamWriter writer =
new
StreamWriter(output))
{
writer.Write(reader.ReadToEnd());
}}
.net 4.5 中流复制的方法:Stream.CopyToAsync
1
2
3
public
Task CopyToAsync(
Stream destination
)
示例:
1
2
3
4
5
6
7
8
9
10
11
12
string
StartDirectory =
@"c:\Users\exampleuser\start"
;
string
EndDirectory =
@"c:\Users\exampleuser\end"
;
foreach
(
string
filename
in
Directory.EnumerateFiles(StartDirectory))
{
using
(FileStream SourceStream = File.Open(filename, FileMode.Open))
{
using
(FileStream DestinationStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf(
'\\'
))))
{
await SourceStream.CopyToAsync(DestinationStream);
}
}
}
.net 4.0 中流复制的方法:Stream.CopyTo
1
2
3
4
5
6
MemoryStream destination =
new
MemoryStream();
using
(FileStream source = File.Open(
@"c:\temp\data.dat"
,FileMode.Open))
{
source.CopyTo(destination);
}
.net 3.5及以下版本 流的复制 需要自己写代码实现
流复制方法一:
public static void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[32768]; long TempPos = input.Position; while (true) { int read = input.Read (buffer, 0, buffer.Length); if (read <= 0) break; output.Write (buffer, 0, read); } input.Position = TempPos;// or you make Position = 0 to set it at the start }
流复制方法二:
1
2
3
4
5
6
public
static
void
CopyStream(Stream input, Stream output){
using
(StreamReader reader =
new
StreamReader(input))
using
(StreamWriter writer =
new
StreamWriter(output))
{
writer.Write(reader.ReadToEnd());
}}
0 0
- C# Stream Copy .net流复制到另一个流
- C#把某个数组的一部分复制到另一个数组中的两种方法:Buffer.BlockCopy和Array.Copy
- 用高效流,将一个图片复制到另一个路径
- oracle10 单向stream流复制
- ASP.NET C#如何读取word,写入word,复制内容到另一个word文档,批量修改文件名
- C#复制文件夹的文件到另一个文件夹
- C#将文件中的图片复制到另一个文件中
- c#将文件从一个位置复制到另一个位置
- C# 复制PDF页面到另一个PDF文档
- C#将文件复制到另一个目录下
- .net 复制DataTable 里面的Row到另一个DataTable
- C#流(stream)
- C#流(stream)
- C#流(stream)
- C#流(stream)
- 流 流复制 stream 高可用
- C# .net Directory Copy
- Node.Js Stream(流)-(四)文件copy实例
- LeetCode-Same Tree
- Mysql数据库——二进制日志
- Jquery实现Ajax用户名实时验证
- xCAT错误Unable to dispatch hierarchical sub-command to NORESOLUTION:3001.
- standby 日志文件切换的问题
- C# Stream Copy .net流复制到另一个流
- 2015年3月3日
- BZOJ 3527 ZJOI 2014 力 FFT
- AmazeUI中控制 li 展开于否的CSS
- onkeyup,onkeydown和onkeypress区别
- C++:函数名后加const
- 《C/C++高质量编程》笔记
- BZOJ 3829 Poi2014 FarmCraft 树形DP+贪心
- 【设计模式】单例模式