Java read file
来源:互联网 发布:mac有自带画图吗 编辑:程序博客网 时间:2024/04/28 20:01
This code will read the MyFile.txt and print its content on theconsole. It reads the file line by line in the form of DataInputStream.
package MyProject
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
*
*/
public class FileInput {
public static void main(String[] args) {
File file = new File("C://MyFile.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
System.out.println(dis.readLine());
}
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- Java read file
- Java read bson file
- file read and write use java
- How to read ini file using Java
- java 读取配置(read config from file)
- File Read
- read file
- Java CSV读--Read And Parse CSV File In Java
- How to read file in Java – BufferedInputStream Example
- A simple way to read an XML file in Java
- Java read and write csv file(注意事项)
- How To Read XML File In Java – (SAX Parser)
- How To Read XML File In Java – (DOM Parser)
- Java – Read a file from resources folder
- Read / Write Excel file in Java using Apache POI
- Read / Write Excel file in Java using Apache POI
- java.io.FileNotFoundException: open failed: EROFS (Read-only file system)
- java.io.IOException: read failed: EBADF (Bad file descriptor)
- 调用方式__cdecl和__stdcall的异同点
- Java Table Examples
- Virtual Keys, Standard Set
- 解决Ubuntu9.04的VMware tools 鼠标和共享文件夹问题
- 视频编码标准H.264的核心技术分析
- Java read file
- .NET : Func委托和Action委托
- 纯手写bmp图片
- PE文件结构分析
- 大小端
- post和get请求的区别
- ORACLE 常用的SQL语法和数据对象
- GetLastError和FormatMessage
- MSFlexGrid 等操作说明(摘自互联网)