2

For example,if my input csv file contains

A    B     C     D      E
10   ab    a1    b1     ab1
20   cd    c1    d1     cd1    
30   ef    e1    f1     ef1
40   gh    c1    h1     gh1

My output..

Enter a value for C
c1
1)
A | 20
B | cd
C | c1
D | d1
E | cd1
2)
A | 40
B | gh
C | c1
D | h1
E | gh1
1
  • first read line and split by tab get the value of 2nd index .if it's user enter value then print all the index Commented Nov 7, 2014 at 11:49

1 Answer 1

1

first read line and split by tab get the value of 2nd index .if it's user enter value then print all the values .for example

void cvsRead() throws FileNotFoundException, IOException {

        String line, userinput = "";
        BufferedReader br = new BufferedReader(new FileReader("yourfile.cvs"));
        Scanner scan = new Scanner(System.in);
        System.out.println("enter the column ");
        userinput = scan.nextLine();
        int i = 0;
        String[] spmap = br.readLine().split("\t");
        while ((line = br.readLine()) != null) {

            String[] sp = line.split("\t");
            if (sp[2].equals(userinput)) {
                i++;
                System.out.println(i + ")");
                for (int x = 0; x < spmap.length; x++) {
                    System.out.println(spmap[x] + " | " + sp[x]);
                }
            }

        }
    }

output>>

enter the column 
c1
1)
A | 20
B | cd
C | c1
D | d1
E | cd1    
2)
A | 40
B | gh
C | c1
D | h1
E | gh1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.