Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. public class Scores extends JPanel {
  2.     public static void main(String[] args){
  3.         ArrayList<String> scores = new ArrayList<>();
  4.         ArrayList<Integer> highScores = new ArrayList<>();
  5. //        try{
  6. //            Scanner fileScanner = new Scanner(new File("C:\\Users\\Jasiul\\Documents\\GitHub\\spaceinvaders\\SpaceInvaders\\src\\spacescores\\scores.txt"));
  7. //            while (fileScanner.hasNextInt()){
  8. //               scores.add(fileScanner.nextInt());
  9. //               for(Integer model : scores) {
  10. //                   String s = Integer.toString(model);
  11. //                   System.out.println("duap" + s + "\n");
  12. //               }
  13. //               System.out.println("line" + scores + "\n");
  14. //            }
  15. //        }
  16. //        catch (Exception e){
  17. //            System.out.println("error" + e.toString());
  18. //        }
  19.        
  20.         //highScores.sort();
  21.         String string = "";
  22.         String file = "highscores.txt";
  23.         //String file2 = "out.txt";
  24.  
  25.         // Reading
  26.         try{
  27.             InputStream ips = new FileInputStream(file);
  28.             InputStreamReader ipsr = new InputStreamReader(ips);
  29.             BufferedReader br = new BufferedReader(ipsr);
  30.             String line;
  31.             while ((line = br.readLine()) != null){
  32.                 System.out.println("line" + line + "\n");
  33.                 //scores.add(line);
  34.                 string += line + "\n";
  35.             }
  36.             br.close();
  37.         }
  38.         catch (Exception e){
  39.             System.out.println(e.toString());
  40.         }
  41.  
  42.         // Writing
  43.         try {
  44.             FileWriter fw = new FileWriter (file);
  45.             BufferedWriter bw = new BufferedWriter (fw);
  46.             PrintWriter fileOut = new PrintWriter (bw);
  47.             fileOut.println (string+"\n test of read and write !!");
  48.             fileOut.close();
  49.             System.out.println("the file " + file + " is created!");
  50.         }
  51.         catch (Exception e){
  52.             System.out.println(e.toString());
  53.         }
  54.        
  55.     }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement