0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

csvfile.java

Last updated at Posted at 2017-12-11

csvfile.java
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import java.nio.file.Files;
import java.nio.file.Paths;
 
class csvfile {
  public static void main(String args[]) {
    // read from csv file
    try (Stream<String> stream = Files.lines(Paths.get(System.getProperty("user.dir"),args[0]))) {
    // read each line
        String data[][] = stream.map(line -> line.split(","))
        .map(line -> Arrays.stream(line)
        .map(String::new)
        .toArray(String[]::new))
        .toArray(String[][]::new);
        
        //debug
        //System.out.println(data[0][0]+data[0][1]+data[0][2]);
        
    } catch (IOException e) {
        e.printStackTrace();
    }
  }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?