Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. ```java
  2.    public boolean sauvegarder(String fileName, String data) {
  3.         FileOutputStream output = null;
  4.         try {
  5.             output = openFileOutput(fileName, MODE_PRIVATE);
  6.             output.write(data.getBytes());
  7.             if(output != null) {
  8.                 output.close();
  9.             }
  10.             return true;
  11.         } catch (FileNotFoundException e) {
  12.             e.printStackTrace();
  13.         } catch (IOException e) {
  14.             e.printStackTrace();
  15.         }
  16.         return false;
  17.     }
  18.  
  19.     public String charger(String fileName){
  20.         String value = null;
  21.         FileInputStream inputStream= null;
  22.         try {
  23.             inputStream = openFileInput(fileName);
  24.  
  25.         StringBuilder stringb= new StringBuilder();
  26.         int content;
  27.  
  28.         while ((content=inputStream.read())!=-1){
  29.             value = String.valueOf(stringb.append((char)content));
  30.         }
  31.         } catch (FileNotFoundException e) {
  32.             e.printStackTrace();
  33.         } catch (IOException e) {
  34.             e.printStackTrace();
  35.         }
  36.         return value ;
  37.     }
  38. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement