Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String fileName = "file.txt";
- /**
- * SAUVEGARDE FICHIER TXT
- */
- public void saveFile(String file, String text)
- {
- try{
- FileOutputStream fos = openFileOutput(file, Context.MODE_WORLD_READABLE);
- fos.write(text.getBytes());
- fos.close();
- Toast.makeText(this, "Sauvegardé avec succès !", Toast.LENGTH_SHORT).show();
- }catch (Exception e){
- e.printStackTrace();
- Toast.makeText(this, "Erreur survenue ...", Toast.LENGTH_SHORT).show();
- }
- }
- /**
- * LECTURE FICHIER
- */
- public String readFile(String file)
- {
- String text = "";
- try{
- FileInputStream fis = openFileInput(file);
- int size = fis.available();
- byte[] buffer = new byte[size];
- fis.read(buffer);
- fis.close();
- text = new String(buffer);
- Toast.makeText(this, "Lecture avec succès !", Toast.LENGTH_SHORT).show();
- }catch (Exception e){
- e.printStackTrace();
- Toast.makeText(this, "Erreur survenue ...", Toast.LENGTH_SHORT).show();
- }
- return text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement