Delphi XE5 Android – save / load file of sdcard

I am using Delphi XE5 for Android development

I like to save TStringList and load it into the text file on the sdcard. When I save TStringList to a file, everything is normal. After saving, I can call loadfromfile and load the file

The problem is that I close the application and open it again. Does the file not exist? This is the file location filename: = '/ data / data / [com. My. App] / files / file. TXT'

Under application user privileges = write to external storage: true

Do I need to save the file to another folder?

Thanks for your help.

This is in my code and settings

procedure LOAD;
var
  TextFile: TStringList;
  FileName: string;
begin
     TextFile := TStringList.Create;
    try
      FileName := Format('%s/File.txt', [GetHomePath]);
      if FileExists(FileName) then
      begin
        TextFile.LoadFromFile(FileName);
        Memo1.Lines.Text := TextFile.Text
      end
      else
        ShowMessage('File not exists!');
    finally
      TextFile.Free;
    end;     

end;

procedure SAVE;
var
  TextFile: TStringList;
  FileName: string;
begin   
    TextFile := TStringList.Create;
    try
      FileName := Format('%s/File.txt', [GetHomePath]);
      TextFile.Text := Memo1.Lines.Text;
      TextFile.SaveToFile(FileName);
    finally
      TextFile.Free;
    end;     
end;

resolvent:

Yes,

AppPath := TPath.GetHomePath; 
FileName := TPath.Combine(AppPath, 'File.txt');

It works well. Don't forget to add the unit system. Ioutils to the uses clause

Thank you, xjernej

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>