Bonjour,
J'ai besoin de stocker une valeur issue d'un calcul ainsi que la date dans un fichier texte. Un enregistrement par ligne. Ces valeurs ne seront utilisées que par l'application.
Je n'ai pas de compétences particulières en développement Android aussi j'ai testé beaucoup de solutions proposées sur internet sans succès pour l'instant.
Où j'en suis:
J'ai demandé la permission dans le manifeste:
Le code pour stocker:Code:
1
2
3
4<!-- ENABLE PERMISSIONS ABOUT EXTERNAL STORAGE ACCESS --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
J'ai essayé les deux versions de code mais j'ai toujours le toast "FileNotFoundException " à l'exécution.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 FileOutputStream fos = null; try { /* String data = Float.toString(resultat); FileWriter fw = new FileWriter(file_name,true); BufferedWriter bw = new BufferedWriter(fw); fw.write(data); fw.close(); */ fos = new FileOutputStream(file_name, true); String data = Float.toString(resultat); fos.write(data.getBytes()); fos.close(); } catch (FileNotFoundException e) { Log.d("DEBUG","FileNotFoundException"); Toast.makeText(MainActivity.this, "FileNotFoundException " + e.getMessage(), Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.d("DEBUG","IOException"); }
Merci pour toute suggestion, modification, etc...