ITeye博客

java读取本地文件

sxlkk · 2018-06-23 15:18 · Core Java · 编程语言 · Markdown

String encoding = this.guessEncoding(filePath + fileName);
            File file = new File(filePath + fileName);
            if (file.isFile() && file.exists()) { //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file), encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    list.add(lineTxt);
                }
                read.close();

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。