V
V
Vampre2019-07-02 15:22:45
Java
Vampre, 2019-07-02 15:22:45

Why is the library not imported in Java?

I'm learning java, I downloaded the jar archive of the opencsv library, I'm trying to import it:

package Char2;

import java.io.FileReader;

import Char2.libs.opencsv.CSVReader;

class Ex13 {
    public static void main(String[] args) {
        CSVReader reader = new CSVReader(new FileReader("csv/t1.csv"));
        String[] nextLn;
        while((nextLn = reader.readNext()) != null) {
            System.out.println(nextLn[0] + nextLn[1] + nextLn[2]);
        }
    }
}

Structure:
Char2/
....libs/
........opencsv.jar
....Ex13.java Run
from terminal: javac -cp Char2/libs/opencsv.jar Char2/ex13.java
When compiling I get error:
Char2/ex13.java:5: error: package Char2.libs does not exist
import Char2.libs.*;
^
Char2/ex13.java:9: error: cannot find symbol
CSVReader reader = new CSVReader(new FileReader("csv/t1.csv"));
^
symbol: class CSVReader
location: class Ex13
Char2/ex13.java:9: error: cannot find symbol
CSVReader reader = new CSVReader(new FileReader("csv/t1.csv"));
^
symbol: class CSVReader
location: class Ex13
3 errors

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-07-02
@sergey-gornostaev

The directive importtakes the name of the package being imported, not the path. It should be like this .
Relevant section of the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question