Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

reader

   public static void main(String[] args) throws IOException {

    Stack stack = new Stack(); 
    Queues queue = new Queues();

    File stackfile = new File("stack.txt"); 


    if (!stackfile.exists()) { 
        stackfile.createNewFile(); 
    } else {
        System.out.println("File is done"); 
    }
    FileReader r= new FileReader(stackfile);
    BufferedReader reader = new BufferedReader(r); 

    String line = null; 
    Data data= new Data(); // this class have String name, surname and string number

    int i=1;
    while ((line=reader.readLine())!=null) { 

        { if(line.trim().equals("#")){
            stack.Push(data);
            data=new Data();
            i=1;
        }
        else{
            if(i==1){
                data.setNo(line);
            }
            else if(i==2){
                data.setName(line);

            }
            else if(i==3){
                data.setSurName(line);
            }
            i++;

            }
        }





    }
    stack.Push(data);
    reader.close();

    File queuefile = new File("queue.txt"); 

    if (!queuefile.exists()) { 
        queuefile.createNewFile(); 
    } else {
        System.out.println("File is done");
    }

    BufferedReader read = null; 
    read = new BufferedReader(new FileReader(queuefile));
    String lines = read.readLine();


    while (lines != null) { 
        System.out.println("Read from queue: " + lines);


         { if(lines.trim().equals("#")){
            queue.insert(data);
            data=new Data();
            i=1;
        }
        else{
            if(i==1){
                data.setNo(line);
            }
            else if(i==2){
                data.setName(line);

            }
            else if(i==3){
                data.setSurName(line);
            }
            i++;

            }
        }


    }
    queue.insert(data);
    read.close();

   }
  }
Comment

PREVIOUS NEXT
Code Example
Java :: how to create hashmap 
Java :: Java String equal String 
Java :: java creating a stack 
Java :: android get string value 
Java :: traversing treemap in java 
Java :: Infinite While Loop Java Example 
Java :: flutter unable to find bundled java version 
Java :: a?che les paramètres de la ligne de commande triés par ordre lexicographique en java 
Java :: java break and continue 
Java :: add java 8 support to pom 
Java :: How to merge two sorted arrays into a single sorted bigger one? 
Java :: round decimals in java string 
Java :: java return new instance of generic type 
Java :: hasNext for scanner class java 
Java :: how to set java path in windows 10 
Java :: leer XML java 
Java :: android java change text value 
Java :: thread priorities in java 
Java :: algorithm to know if a number is an integer 
Java :: android activity keyboard hide 
Java :: java class array of objects 
Java :: intellij set target bytecode version 
Java :: java sub method 
Java :: what is delegation in java 
Java :: expression régulière téléphone java 
Java :: de caracter a string en java 
Java :: arraylist replace 
Java :: get runtime java 
Java :: java animated gif example 
Java :: sending a excel in an attachment in email java 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =