1. 程式人生 > >Java讀取CSV檔案

Java讀取CSV檔案

新增依賴庫

		<dependency>
            <groupId>net.sourceforge.javacsv</groupId>
            <artifactId>javacsv</artifactId>
            <version>2.0</version>
        </dependency>

Java程式碼

CsvReader r;
String csvFilePath = "C:\\搜狗app.csv";
try {
	r = new CsvReader
(new FileInputStream(csvFilePath), ',', Charset.forName("GBK")); int i = 0; while (r.readRecord()) { if (skipRow != i) { if (i >= rowOffset) { for (int j = 0; j < r.getColumnCount(); j++) { System.out.print(r.get(j) + " "); } System.out.println(); } } i++; } } catch
(FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }