Bonjour,
Débutant avec Android, je voudrais voir comment on lit et écrit dans un fichier.
J'ai trouvé ce code qui doit créer un fichier MyFile.txt
Quand j'exécute sur une tablette Samsung Galaxy Tab E, le premier ShowMessage me donne le fichier :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 procedure TForm1.Button2Click(Sender: TObject); var TextFile : TStringList; FileName : string; begin try textFile := TStringList.Create; try {$IFDEF ANDROID}//if the operative system is Android FileName := Format('%smyFile.txt',[GetHomePath]); {$ENDIF ANDROID} {$IFDEF WIN32} FileName := Format('%smyFile.txt',[ExtractFilePath(ParamStr(0))]); {$ENDIF WIN32} ShowMessage('Fichier : '+Filename ) ; if FileExists(FileName) then begin textFile.LoadFromFile(FileName); //load the file in TStringList showmessage(textfile.Text);//there is the text end else begin showMessage('File not exists, Create New File'); TextFile.Text := 'There is a new File (Here the contents)'; TextFile.SaveToFile(FileName);//create a new file from a TStringList end; finally textFile.Free; end; except on E : Exception do ShowMessage('ClassError: '+e.ClassName+#13#13+'Message: '+e.Message); end; end;
/data/data/com.embarcadero.project1/filesmyfile.txt
Mais quand je regarde sur la tablette, par de répertoire data/data/... seulement data/...
D'autre part, une recherche ne localise pas le fichire myFile.txt ?
Ce fichier est il bien créé par le SaveToFile et ou est il passé ?
A+
Charly
Partager