java 读取并且显示 txt 文件
2014-05-14 03:29
627 查看
系统:mac os x 10.9
eclipse
在eclipse 中建立一个project, 命名为Cin_txt,
Cin_txt的内容
以下是输入的代码
JDK7 版本
eclipse
在eclipse 中建立一个project, 命名为Cin_txt,
Cin_txt的内容
test wang hello world
以下是输入的代码
import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Cin_txt { public static void main(String[] args) { File file = new File("/Users/yinjiewang/Documents/test.txt"); FileInputStream fis = null; try { fis = new FileInputStream(file); System.out.println("Total file size to read (in bytes) : " + fis.available()); int content; while ((content = fis.read()) != -1) { // convert to char and display it System.out.print((char) content); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) fis.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }
JDK7 版本
import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class ReadFileExample { public static void main(String[] args) { File file = new File("C:/robots.txt"); try (FileInputStream fis = new FileInputStream(file)) { System.out.println("Total file size to read (in bytes) : "+ fis.available()); int content; while ((content = fis.read()) != -1) { // convert to char and display it System.out.print((char) content); } } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- 获取文件夹大小并且显示为易于读取的文件单位
- 利用JAVA/JSF/JSP实现读取并截取.txt文件http://zhidao.baidu.com/question/42189115.html
- Java读取UTF-8格式txt文件第一行出现乱码——问号“?”及解决;Java读带有BOM的UTF-8文件乱码原因及解决方法
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法
- Java读取远程服务器上的txt文件
- 从一个txt文件中读取文章并删除特定单词并显示文章
- 从txt文件中读取数字 java
- 使用Robot从txt文件中读取不同行的内容并显示
- Java读取txt文件 copy文件 写入文件
- java 读取资源文件并且动态设置资源里面的参数demo
- 运用JAVA读取txt文件(BufferReader)
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- 使用Robot从txt文件中读取不同行的内容并显示(续)
- 用Delphi如何读取Wav文件的波形,并且显示?
- ASP读取显示TXT文件内容
- 用ASP读取显示TXT文件内容的代码
- JAVA读取txt文件中数据代码范例
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例