Advertisement
NB52053

ArrayListSample

Aug 12th, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. ///
  2.  
  3. List<String> words = new ArrayList<String>();
  4. BufferedReader reader = new BufferedReader(new FileReader("words.txt"));
  5. String line;
  6. while ((line = reader.readLine()) != null) {
  7.     words.add(line);
  8. }
  9. reader.close();
  10.  
  11.  
  12. -----------------------------------------------------------------------
  13. BufferedReader in = null;
  14. List<String> myList = new ArrayList<String>();
  15. try {  
  16.     in = new BufferedReader(new FileReader("myfile.txt"));
  17.     String str;
  18.     while ((str = in.readLine()) != null) {
  19.         myList.add(str);
  20.     }
  21. } catch (FileNotFoundException e) {
  22.     e.printStackTrace();
  23. } catch (IOException e) {
  24.     e.printStackTrace();
  25. } finally {
  26.     if (in != null) {
  27.         in.close();
  28.     }
  29. }
  30. -------------------------------------------------------------------------------------------------------------------
  31.  
  32. ---------------------------------ARRRAY EXAMPLE -------------------------------------------------------------------
  33. BufferedReader in = new BufferedReader(new FileReader("path/of/text"));
  34.         String str;
  35.  
  36.         while((str = in.readLine()) != null){
  37.             String[] arr = str.split(" ");
  38.             for(int i=0 ; i<str.length() ; i++){
  39.                 arr[i] = in.readLine();
  40.             }
  41.         }
  42.  
  43.  
  44. PrintWritter
  45.  
  46. BufferedReader reader = new BufferedReader(new FileReader(file));
  47. String line = null;      
  48. while(s=br.readline()!=null) {
  49.       PrintWriter fs = new PrintWriter(new FileWriter(file));
  50.       fs.println(s);
  51. }
  52. ------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement