daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package FileReadWriter;
  2.  
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.util.List;
  8. import java.util.stream.Collectors;
  9. import java.util.stream.Stream;
  10.  
  11. public class Data {
  12.    
  13.     public static List<String> readData() {
  14.         List<String> lines = null;
  15.         try(Stream<String> x = Files.lines(Paths.get("c:\\temp\\fuck.txt"))){
  16.             lines = x.collect(Collectors.toList());
  17.         }
  18.         catch(IOException e) {
  19.             System.out.println(e.getMessage());
  20.         }
  21.         return lines;
  22.     }
  23.  
  24.     public static void writeData(List<String> x) {
  25.         FileWriter fw;
  26.         try {
  27.             fw = new FileWriter("c:\\temp\\fuck.txt");
  28.             for(String str :  x)
  29.                 fw.write(str+"\n");
  30.             fw.flush();
  31.             fw.close();
  32.         } catch (IOException e) {
  33.             e.printStackTrace();
  34.         }
  35.     }
  36.  
  37.    
  38.     public static void addData(String line) {
  39.         List<String> x = readData();
  40.         if(!x.contains(line)) {
  41.             x.add(line);
  42.             writeData(x);
  43.         }
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47.         System.out.println(readData());
  48.         addData("Fucker,10100101");
  49.         System.out.println(readData());
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top