1) var f1 : File; begin Assign(f1,'xxxx'); blockRead(f1,buf,len); end;2) var fs : tFileStream; ms : tMemoryStream; begin fs := TFileStream.Create("xxx"); ms := TMemoryStream.Create; ms.LoadFromStream(fs); end;3) ms.loadFromFile('xxxx') //ms是 TMemoryStream;
目的:加密一数据库文件. 步踌:读入数据库文件(1.db)到串(a)中,取出串中每个字符的ascii(function ord),通过一定方式的运算,得到新的串,返回字符(function chr),再写入到文件(1.db) 问题:只能将数据库文件(1.db)的一部分读入,但该程序对文本文件一切正常. 拜托帮忙改正一下,谢谢 源程序: var f1,f2:textfile; test:ansistring; a:char; b,code:integer; c:string;begin assignfile(f1,'c:\1'); assignfile(f2,'c:\2'); reset(f1); rewrite(f2);while not eof(f1) do begin while not eoln(f1) do begin read(f1,test); len:=length(test); for i:=1 to len do begin a:=test[i]; b:=ord(a); str(b,c); if length(c)<2 then c:='00'+c else if length(c)<3 then c:='0'+c; write(f2,c); end; end; readln(f1); writeln(f2); end;
var
f1 : File;
begin
Assign(f1,'xxxx');
blockRead(f1,buf,len);
end;2)
var
fs : tFileStream;
ms : tMemoryStream;
begin
fs := TFileStream.Create("xxx");
ms := TMemoryStream.Create;
ms.LoadFromStream(fs);
end;3)
ms.loadFromFile('xxxx') //ms是 TMemoryStream;
步踌:读入数据库文件(1.db)到串(a)中,取出串中每个字符的ascii(function ord),通过一定方式的运算,得到新的串,返回字符(function chr),再写入到文件(1.db)
问题:只能将数据库文件(1.db)的一部分读入,但该程序对文本文件一切正常.
拜托帮忙改正一下,谢谢
源程序:
var
f1,f2:textfile;
test:ansistring;
a:char;
b,code:integer;
c:string;begin
assignfile(f1,'c:\1');
assignfile(f2,'c:\2');
reset(f1);
rewrite(f2);while not eof(f1) do
begin
while not eoln(f1) do
begin
read(f1,test);
len:=length(test);
for i:=1 to len do
begin
a:=test[i];
b:=ord(a);
str(b,c);
if length(c)<2 then c:='00'+c else
if length(c)<3 then c:='0'+c;
write(f2,c);
end;
end;
readln(f1);
writeln(f2);
end;