先看下面的程序using System;
using System.IO;class FileRWRandom
{
static void Main()
{ Console.WriteLine("输入所要读取的文件名称 :");
string readFileName = Console.ReadLine();
Console.WriteLine("输入开始读取的位置 :");
int position = int.Parse(Console.ReadLine());
Console.WriteLine("输入所要复制的文件名称 :");
string writFILEeName = Console.ReadLine(); FileStream FileReadStream = new FileStream
(readFileName, FileMode.Open, FileAccess.Read);
FileReadStream.Position = position; FileStream FileWriteStream = new FileStream
(writFILEeName, FileMode.Create, FileAccess.Write); byte[] b = new byte[512];
int intRead = 0;
intRead = FileReadStream.Read(b, 0, b.Length);
Console.WriteLine("总共读取 " + intRead + " 个字节 !!");
FileWriteStream.Write(b, 0, intRead); FileReadStream.Close();
FileWriteStream.Close(); Console.Read(); }
}我复制的源文件一部分内容是:
cysui 9AC.9B0 0000 00:00:13:29.0718 opening log file C:\WINDOWS\debug\cysui.log
cysui 9AC.9B0 0001 00:00:13:29.0718 C:\WINDOWS\system32\cys.exe
cysui 9AC.9B0 0002 00:00:13:29.0718 file timestamp 02/17/2007 06:59:50.000
cysui 9AC.9B0 0003 00:00:13:29.0718 local time 03/22/2009 09:35:55.968
cysui 9AC.9B0 0004 00:00:13:29.0718 running Windows NT 5.2 build 3790 Service Pack 2 (BuildLab:3790.srv03_sp2_gdr.080813-1204) i386
cysui 9AC.9B0 0005 00:00:13:29.0718 logging flags 000100BC
cysui 9AC.9B0 0006 00:00:13:29.0765 Enter Start
cysui 9AC.9B0 0007 00:00:13:29.0765 Enter IsCurrentUserAdministrator
cysui 9AC.9B0 0008 00:00:13:29.0765 Current user is an admin
cysui 9AC.9B0 0009 00:00:13:29.0765 Enter Computer::RemoveLeadingBackslashes
cysui 9AC.9B0 000A 00:00:13:29.0765 Enter Computer::Refresh
cysui 9AC.9B0 000B 00:00:13:29.0765 Enter IsLocalComputer
cysui 9AC.9B0 000C 00:00:13:29.0765 Enter RefreshLocalInformation
cysui 9AC.9B0 000D 00:00:13:29.0765 Enter GetProductTypeFromRegistry
cysui 9AC.9B0 000E 00:00:13:29.0765 Enter RegistryKey::Open
设置Position的值为:1得到的复制后的文件为: y s u i 9 A C . 9 B 0 0 0 0 0 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 o p e n i n g l o g f i l e C : \ W I N D O W S \ d e b u g \ c y s u i . l o g
c y s u i 9 A C . 9 B 0 0 0 0 1 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 C : \ W I N D O W S \ s y s t e m 3 2 \ c y s . e x e
c y s u i 9 A C . 9 B 0 0 0 0 2 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 f i l e t i m e s t a m p 0 2 / 1 7 / 2 0 0 7 0 6 : 5 9 : 5 0 . 0 0 0
c y s u i 9 A C . 9 B 0 0 0 0 3 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1请问这是为什么,你可以自己上机试试
using System.IO;class FileRWRandom
{
static void Main()
{ Console.WriteLine("输入所要读取的文件名称 :");
string readFileName = Console.ReadLine();
Console.WriteLine("输入开始读取的位置 :");
int position = int.Parse(Console.ReadLine());
Console.WriteLine("输入所要复制的文件名称 :");
string writFILEeName = Console.ReadLine(); FileStream FileReadStream = new FileStream
(readFileName, FileMode.Open, FileAccess.Read);
FileReadStream.Position = position; FileStream FileWriteStream = new FileStream
(writFILEeName, FileMode.Create, FileAccess.Write); byte[] b = new byte[512];
int intRead = 0;
intRead = FileReadStream.Read(b, 0, b.Length);
Console.WriteLine("总共读取 " + intRead + " 个字节 !!");
FileWriteStream.Write(b, 0, intRead); FileReadStream.Close();
FileWriteStream.Close(); Console.Read(); }
}我复制的源文件一部分内容是:
cysui 9AC.9B0 0000 00:00:13:29.0718 opening log file C:\WINDOWS\debug\cysui.log
cysui 9AC.9B0 0001 00:00:13:29.0718 C:\WINDOWS\system32\cys.exe
cysui 9AC.9B0 0002 00:00:13:29.0718 file timestamp 02/17/2007 06:59:50.000
cysui 9AC.9B0 0003 00:00:13:29.0718 local time 03/22/2009 09:35:55.968
cysui 9AC.9B0 0004 00:00:13:29.0718 running Windows NT 5.2 build 3790 Service Pack 2 (BuildLab:3790.srv03_sp2_gdr.080813-1204) i386
cysui 9AC.9B0 0005 00:00:13:29.0718 logging flags 000100BC
cysui 9AC.9B0 0006 00:00:13:29.0765 Enter Start
cysui 9AC.9B0 0007 00:00:13:29.0765 Enter IsCurrentUserAdministrator
cysui 9AC.9B0 0008 00:00:13:29.0765 Current user is an admin
cysui 9AC.9B0 0009 00:00:13:29.0765 Enter Computer::RemoveLeadingBackslashes
cysui 9AC.9B0 000A 00:00:13:29.0765 Enter Computer::Refresh
cysui 9AC.9B0 000B 00:00:13:29.0765 Enter IsLocalComputer
cysui 9AC.9B0 000C 00:00:13:29.0765 Enter RefreshLocalInformation
cysui 9AC.9B0 000D 00:00:13:29.0765 Enter GetProductTypeFromRegistry
cysui 9AC.9B0 000E 00:00:13:29.0765 Enter RegistryKey::Open
设置Position的值为:1得到的复制后的文件为: y s u i 9 A C . 9 B 0 0 0 0 0 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 o p e n i n g l o g f i l e C : \ W I N D O W S \ d e b u g \ c y s u i . l o g
c y s u i 9 A C . 9 B 0 0 0 0 1 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 C : \ W I N D O W S \ s y s t e m 3 2 \ c y s . e x e
c y s u i 9 A C . 9 B 0 0 0 0 2 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1 8 f i l e t i m e s t a m p 0 2 / 1 7 / 2 0 0 7 0 6 : 5 9 : 5 0 . 0 0 0
c y s u i 9 A C . 9 B 0 0 0 0 3 0 0 : 0 0 : 1 3 : 2 9 . 0 7 1请问这是为什么,你可以自己上机试试
解决方案 »
- C#作为外部进程被调用如何获得该C#进程而不是主进程的当前所在的目录
- C#复选框CheckBox控件实现问题
- Developer里gridControl使用问题 前辈赐教
- DataTable类型数据插入到数据库
- 如何给密码框付初值
- 怎么历遍一个窗体所有字控件,然后得到自己想要控件的句柄?
- javascript问题!高手请进。
- c# 弹球游戏 礼物类
- 请教大哥!!! :)
- 【加急】devexpress layoutcontrol 边框显示问题
- 就是通过DATASET读出的数据,写一个JS,JS实现把这些数据写到网页上
- 在button上设置图片用BackgroundImage、BackgroundLayout属性为Stretch,但执行button的Enabled属性后,图片的颜色不变(即不会变淡),谁有办法解决。
复制后的文件为
i 9AC.9B0 0000 00:00:13:29.0718 opening log file C:\WINDOWS\debug\cysui.log
cysui 9AC.9B0 0001 00:00:13:29.0718 C:\WINDOWS\system32\cys.exe
cysui 9AC.9B0 0002 00:00:13:29.0718 file timestamp 02/17/2007 06:59:50.000
cysui 9AC.9B0 0003 00:00:13:29.0718 lo看的出来是从源文件的第5个字符开始复制的,难道文本文件是以Unicode方式打开文件的?2个2个字节读?
而FileStream.Positon的设置是以一个字节为单位?
所以复制后第一个字符乱码