---
title: "java读取本地文件"
author: "sxlkk"
date: "2018-06-23T15:18:30Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2018-06-23T15:18:30Z"
id: 2425459
url: "https://sxlkk.iteye.com/blog/2425459"
---

```
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();
```