Java用IO读取文件内容出现错误
2018-03-21 18:17
204 查看
使用java读取文件信息,可以用以下方法,如果是读取包内的一个文件夹内的文件,
可以使用例如"maps/map.txt"的方式进行读取文件。
但是在读取过程中有时会出现FileNotFoundException的错误,很有可能是因为读取的文件的编码格式不是
UTF-8引起错误的,可以使用这种方法进行修改:
选择文件→另存为
编码选择UTF-8,这样就不会出错了。try {File file = new File("filename");FileReader fileReader = new FileReader(file.getName());BufferedReader bufferedReader = new BufferedReader(fileReader);String en="";// int n=0;while((en=bufferedReader.readLine())!=null){if(en.equals("cloud"))System.out.println("have cloud");}bufferedReader.close();}catch (IOException e){e.printStackTrace();}
相关文章推荐
- struts2文件下载 出现Can not find a java.io.InputStream with the name的错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- Java中从txt文件中读取和存储内容出现乱码的解决之道一:
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- Java 简单解决springmvc获取properties文件里面中文内容出现论码问题(我遇到的问题是数据提交检验时返回的错误提示出现乱码)
- struts2下载文件时出现:java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to 错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- java IO体系中读取文件文本文件中内容
- JAVA_IO_字符流读取文件内容
- JavaIO读取文件内容
- JAVA语言IO读取文件内容
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- java IO体系中读取文件文本文件中内容
- Java:InputStream读取文本文件内容出现乱码问题的解决方法
- struts2下载文件时出现:java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to 错误
- java读取文件内容按照值出现的次数排序
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- 编写IoDemo.java的Java应用程序,程序完成的功能是:首先读取text.txt文件内容,再通过键盘输入文件的名称为iodemo.txt,把text.txt的内容存入iodemo.txt
- 遇到问题----struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误