Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

queue and stack 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 :: Java How to use Map? 
Java :: final vs static keyword in java 
Java :: pass a function as parameter 
Java :: initilize an array java 
Java :: java how to change the length of an array 
Java :: how to declare jtextfield 
Java :: Java Create a BufferedOutputStream 
Java :: android studio reg get float from numeric string 
Java :: java try-with-resources 
Java :: how to add arms to armor stands 1.16 Java Edition 
Java :: How to merge two sorted arrays in Java? 
Java :: run webgoat using docker 
Java :: java add a list to a list 
Java :: change short video to byte array android 
Java :: java do while loop example 
Java :: locked screen android studio 
Java :: pdf intent does not have permission to launch 
Java :: count true in matrix java 
Java :: app not showing in share menu android 
Java :: android java show hide keyboard in AndroidManifest 
Java :: how to merge two arrays in java 
Java :: java creare costante 
Java :: java sub function 
Java :: react-native force light mode 
Java :: jsoup remove element 
Java :: Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8 
Java :: where to use findviewbyid in fragment 
Java :: measure view height android 
Java :: djava days between two dates 
Java :: java string strip 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =