delphi 파일 읽기

1762 단어
procedure TForm_main.Button5Click(Sender: TObject);
var
  myStream:TFileStream;
  myFileSize:Integer;
  myTextFile:TextFile;
  text,data,fileStr:string;
  fileData:TStringList;
  memory:TMemoryStream;
  stringStream: TStringStream;
  buffer:PChar;
  resource:TResourceStream;
  jj:TCustomMemoryStream;
  MyWrite:TWriter;
  MyReader:TReader;
begin
  //          
  //myStream:=TFileStream.Create('');
  AssignFile(myTextFile,Edit1.Text);
  Reset(myTextFile);
  while not Eof(myTextFile) do
  begin
    readln(myTextFile,text);
    data:=data+text;
    //ShowMessage(text);
  end;
  CloseFile(myTextFile);
  //ShowMessage(data);
  //TStringList     
  fileData:=TStringList.Create;
  fileData.LoadFromFile(Edit1.Text);
  //ShowMessage('  :'+inttostr(fileData.Count));
  //Application.MessageBox(PWideChar(fileData.Text),'    ',0);
  fileData.Free;
  //TFileStream     
  myStream:=TFileStream.Create(Edit1.Text,fmShareDenyRead);
  myStream.Position:=0;
  //myStream.Seek(0);
  GetMem(buffer,myStream.Size);
  //SetLength(buffer,myStream.Size);
  myStream.Read(buffer^,myStream.Size);
  ShowMessage(buffer);
  fileStr:=Pchar(@buffer[0]);
  ShowMessage(fileStr);
   // TReader  TWriter
  //MyReader:=TReader.Create(myStream,myStream.Size);
 // filestr:=  MyReader.ReadString;
 // ShowMessage(fileStr);
  FreeAndNil(myStream);
  //
  memory:=TMemoryStream.Create;
  memory.LoadFromFile(Edit1.Text);
  //memory.SaveToFile('test.txt');
  memory.ReadBuffer(buffer^,memory.Size);
  ShowMessage(memory.ToString);
  ShowMessage(buffer);

  //TStringStream    
  stringStream:=TStringStream.Create;
  stringStream.LoadFromFile(Edit1.Text);
  ShowMessage(stringStream.DataString);
  stringStream.Free;

end;

좋은 웹페이지 즐겨찾기