Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advanced;
- import java.io.*;
- import java.util.Random;
- public class MainIO {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- //1. feladat
- ObjectOutputStream IOExample11 = new ObjectOutputStream (new FileOutputStream ("d:/zimmgy/AIOex1.bin"));
- Random R = new Random();
- int[] Marks;
- String[] ListNames = new String[]{"Zimmermann Gyula", "Graion Dilach", "Junichi Nakatsuru"};
- Tanulo[] ListTanulos = new Tanulo[ListNames.length];
- for (int j = 0; j<ListTanulos.length; j++){
- Marks = new int[4];
- for (int i = 0; i < 4; i++) {
- do {
- Marks[i] = (R.nextInt()%5)+1;
- } while (Marks[i] < 1);
- }
- ListTanulos[j] = new Tanulo(ListNames[j], Marks);
- System.out.println(ListTanulos[j].toString());
- IOExample11.writeObject(ListTanulos[j]);
- }
- IOExample11.close();
- ObjectInputStream IOExample12 = new ObjectInputStream (new FileInputStream ("d:/zimmgy/AIOex1.bin"));
- for (int j = 0; j < ListTanulos.length; j++){
- System.out.println(((Tanulo)(IOExample12.readObject())).toString());
- }
- //2. feladat
- //todo- EOL hülye --'
- StreamTokenizer IOExample2 = new StreamTokenizer (new FileReader ("d:/zimmgy/AIOex1.bin"));
- int WordCount =0, NumberCount=0;
- int temp;
- while ((temp = IOExample2.nextToken()) != StreamTokenizer.TT_EOF){
- if(temp == StreamTokenizer.TT_WORD){
- WordCount++;
- }else{
- NumberCount++;
- }
- }
- System.out.println("Szavak száma: " + WordCount + ", számok száma : " + NumberCount);
- //3. feladat
- File Example = new File("d:/zimmgy");
- String[] StuffInIt = Example.list();
- for (int i=0; i<StuffInIt.length; i++){
- System.out.println(StuffInIt[i]);
- }
- }
- catch (Exception e){
- System.out.println ("Who cares, let's annihilate them!");
- }
- }
- }
- =============================================================================================
- package Advanced;
- import java.io.Serializable;
- @SuppressWarnings("serial")
- public class Tanulo implements Serializable{
- String Name;
- int[] Marks;
- Tanulo (String _Name, int[] _Marks){
- Name = _Name;
- Marks = _Marks;
- }
- public String toString(){
- return Name + ", jegyei: " + Marks[0] + ", " + Marks[1]
- + ", " + Marks[2] + ", " + Marks[3] + ", ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement