Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

system program j

import java.io.*;

public class StudentFile
{
    String studentFilePath;
    String student;
    String gender;
    String cgpa_str;
    double cgpa;

    StudentFile(String path)
    {
        studentFilePath = path;
    }


    void display_gender_br(String gndr) throws IOException, FileNotFoundException
    {
        File student_file = new File(studentFilePath);

        FileReader student_reader = new FileReader(student_file);
        BufferedReader student_lines = new BufferedReader(student_reader);


        while ((student = student_lines.readLine()) != null)
        {
            gender = student.split(",")[4];
            if (gender.equals(gndr))
                System.out.println(student);
        }

        student_reader.close();
        student_lines.close();
    }

    void display_cgpa_br(double min, double max) throws IOException, FileNotFoundException
    {
        File student_file = new File(studentFilePath);

        FileReader student_reader = new FileReader(student_file);
        BufferedReader student_lines = new BufferedReader(student_reader);


        while ((student = student_lines.readLine()) != null)
        {
            cgpa_str = student.split(",")[2];
            cgpa = Double.valueOf(cgpa_str);

            if (cgpa>=min && cgpa<=max)
                System.out.println(student);
        }


        student_reader.close();
        student_lines.close();
    }


    // File format : 6235,Kim Blue                      ,1.85,15-04-1992,F
    // id     :  4 bytes
    // name   : 30 bytes
    // cgpa   :  4 bytes
    // date   : 10 bytes
    // gender :  1 byte
    // commas :  4 bytes
    // CR LF  :  2 bytes
    // TOTAL  : 55 bytes

    void display_gender_racc(String gndr) throws IOException {
        File student_file = new File(studentFilePath);
        RandomAccessFile std_file = null;
        try {
            std_file = new RandomAccessFile(student_file, "r");

            String gender = null;
            String std_rec = null;
            String[] fields;

            while (std_file.getFilePointer() <= std_file.length() - 2) // checking the end of file
            {
                std_rec = std_file.readLine();
                fields = std_rec.split(",");
                gender = fields[4];

                if (gender.equals(gndr))
                    System.out.println(std_rec);
            }


        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            std_file.close();
        }
    }

        void display_gender_racc2(String gndr) throws IOException {
            File student_file = new File(studentFilePath);
            RandomAccessFile std_file = null;
            try {
                std_file = new RandomAccessFile(student_file, "r");

                String gender = null;
                String std_rec = null;
                String[] fields;

                byte[] rec = new byte[53];

                while(std_file.getFilePointer() <= std_file.length()-2) // checking the end of file
                {
                    std_file.read(rec, 0, 53);
                    std_rec = new String(rec);

                    std_file.seek(std_file.getFilePointer()+2);

                    fields = std_rec.split(",");

                    gender = fields[4];

                    if (gender.equals(gndr))
                        System.out.println(std_rec);
                }


            } catch (UnsupportedEncodingException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally
            {
                std_file.close();
            }
    }
}
Comment

system program j

import java.io.*;

public class StudentFile
{
    String studentFilePath;
    String student;
    String gender;
    String cgpa_str;
    double cgpa;

    StudentFile(String path)
    {
        studentFilePath = path;
    }


    void display_gender_br(String gndr) throws IOException, FileNotFoundException
    {
        File student_file = new File(studentFilePath);

        FileReader student_reader = new FileReader(student_file);
        BufferedReader student_lines = new BufferedReader(student_reader);


        while ((student = student_lines.readLine()) != null)
        {
            gender = student.split(",")[4];
            if (gender.equals(gndr))
                System.out.println(student);
        }

        student_reader.close();
        student_lines.close();
    }

    void display_cgpa_br(double min, double max) throws IOException, FileNotFoundException
    {
        File student_file = new File(studentFilePath);

        FileReader student_reader = new FileReader(student_file);
        BufferedReader student_lines = new BufferedReader(student_reader);


        while ((student = student_lines.readLine()) != null)
        {
            cgpa_str = student.split(",")[2];
            cgpa = Double.valueOf(cgpa_str);

            if (cgpa>=min && cgpa<=max)
                System.out.println(student);
        }


        student_reader.close();
        student_lines.close();
    }


    // File format : 6235,Kim Blue                      ,1.85,15-04-1992,F
    // id     :  4 bytes
    // name   : 30 bytes
    // cgpa   :  4 bytes
    // date   : 10 bytes
    // gender :  1 byte
    // commas :  4 bytes
    // CR LF  :  2 bytes
    // TOTAL  : 55 bytes

    void display_gender_racc(String gndr) throws IOException {
        File student_file = new File(studentFilePath);
        RandomAccessFile std_file = null;
        try {
            std_file = new RandomAccessFile(student_file, "r");

            String gender = null;
            String std_rec = null;
            String[] fields;

            while (std_file.getFilePointer() <= std_file.length() - 2) // checking the end of file
            {
                std_rec = std_file.readLine();
                fields = std_rec.split(",");
                gender = fields[4];

                if (gender.equals(gndr))
                    System.out.println(std_rec);
            }


        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            std_file.close();
        }
    }

        void display_gender_racc2(String gndr) throws IOException {
            File student_file = new File(studentFilePath);
            RandomAccessFile std_file = null;
            try {
                std_file = new RandomAccessFile(student_file, "r");

                String gender = null;
                String std_rec = null;
                String[] fields;

                byte[] rec = new byte[53];

                while(std_file.getFilePointer() <= std_file.length()-2) // checking the end of file
                {
                    std_file.read(rec, 0, 53);
                    std_rec = new String(rec);

                    std_file.seek(std_file.getFilePointer()+2);

                    fields = std_rec.split(",");

                    gender = fields[4];

                    if (gender.equals(gndr))
                        System.out.println(std_rec);
                }


            } catch (UnsupportedEncodingException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally
            {
                std_file.close();
            }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: what happens if you return only -1 and 1bute not 0 java 
Java :: Create hashmap from another maps java 
Java :: empty string databinding android 
Java :: pioneer meaning 
Java :: how to generate a random number in libgdx 
Java :: Java array with objects from different types 
Java :: snapshot for loop android java 
Java :: How to disable special characters on keyboard in android 
Java :: Program to check Vowel or Consonant using Switch Case 
Java :: Java remove element at position from array and shift 
Java :: cannot apply java lang integer android 
Java :: array remove duplicate in java 
Java :: java search tree 
Java :: java optional parameters 
Java :: comparable 
Java :: file handling in java 
Java :: camel java 
Java :: connecting to h2 database from java 
Java :: search in 2d matrix 
Java :: number of matches regex java 
Java :: javafx load image from resources 
Java :: get image from resourcestream javafx 
Java :: get random word from xz file 
Sql :: search text in all sql server stored procedure 
Sql :: service postgres status 
Sql :: forgot mysql root password stackoverflow 
Sql :: oracle get current schema 
Sql :: wilayah indonesia database 
Sql :: mysql convert timestamp to date 
Sql :: restart postgresql.service Failed to restart postgresql.service: Unit not found. 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =