Answers for "reader"

0

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();

   }
  }
Posted by: Guest on April-20-2021
0

screen reader text

/* Text meant only for screen readers. */
.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}
Posted by: Guest on January-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language