AW: Android SD-Kartenzugriff
Das gehört zu meinem Helper Functions Link.
Zitat:
Hier in der DP gibts auch Infos zu diesem Thema! Saving data to a file in your Android application geht da anders vor. Zum Schreiben:
Delphi-Quellcode:
zum Lesen:
try {
// Creates a file in the primary external storage space of the // current application. // If the file does not exists, it is created. File testFile = new File(this.getExternalFilesDir(null), "TestFile.txt"); if (!testFile.exists()) testFile.createNewFile(); // Adds a line to the file BufferedWriter writer = new BufferedWriter(new FileWriter(testFile, true /*append*/)); writer.write("This is a test file."); writer.close(); // Refresh the data so it can seen when the device is plugged in a // computer. You may have to unplug and replug the device to see the // latest changes. This is not necessary if the user should not modify // the files. MediaScannerConnection.scanFile(this, new String[]{testFile.toString()}, null, null); } catch (IOException e) { Log.e("ReadWriteFile", "Unable to write to the TestFile.txt file."); }
Delphi-Quellcode:
Source Code Link davon
String textFromFile = "";
// Gets the file from the primary external storage space of the // current application. File testFile = new File(this.getExternalFilesDir(null), "TestFile.txt"); if (testFile != null) { StringBuilder stringBuilder = new StringBuilder(); // Reads the data from the file BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(testFile)); String line; while ((line = reader.readLine()) != null) { textFromFile += line.toString(); textFromFile += "\n"; } reader.close(); } catch (Exception e) { Log.e("ReadWriteFile", "Unable to read the TestFile.txt file."); } } Klappt es damit? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz