Java分隔符读取文件

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileWithDelimiter {
    public static void main(String[] args) {
        String filePath = "path_to_file";
        String delimiter = ",";

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] values = line.split(delimiter);
                // process each value
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

你可能感兴趣的