Advertisement
Guest User

Untitled

a guest
May 21st, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication19;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.util.StringTokenizer;
  14.  
  15. /**
  16.  *
  17.  * @author student
  18.  */
  19. public class JavaApplication19 {
  20.  
  21.     /**
  22.      * @param args the command line arguments
  23.      */
  24.     public static void main(String[] args) {
  25.         int l = 0;
  26.         String linie = null;
  27.         PrintWriter fout = null;
  28.         BufferedReader fin = null;
  29.         String nume,prenume;
  30.         double nota;
  31.         int prezenta;
  32.         try {
  33.             fout = new PrintWriter(new FileWriter("linefile.txt"));
  34.             fout.println("Pop,Vasile");
  35.             fout.println("4,12");
  36.             fout.close();
  37.             fin = new BufferedReader(new FileReader("linefile.txt"));
  38.            
  39.             linie = fin.readLine();
  40.             System.out.println("S-a citit linia: " + linie);
  41.             StringTokenizer t = new StringTokenizer(linie, ","); //extragerea simbolurilor pe baza separatorului ,
  42.             nume = t.nextToken();
  43.             prenume = t.nextToken();
  44.            
  45.             linie = fin.readLine();
  46.             System.out.println("S-a citit linia: " + linie);
  47.             t = new StringTokenizer(linie, ",");
  48.             nota = Double.parseDouble(t.nextToken());
  49.             prezenta = Integer.parseInt(t.nextToken());
  50.  
  51.             System.out.println(nume +" "+ prenume +" nota:"+ nota +" prezente:"+ prezenta);
  52.             fin.close();
  53.         } catch (IOException e) {
  54.         }
  55.     }
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement