文件目录:
代码:
package Operation;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class ReadFileInputStream {
public static void main(String[] args) {
File f = new File("db.properties");
try {
InputStream input = new FileInputStream(f);
byte[] b = new byte[100];
int length =0;
int count =0;
/**
* 循环获取数据,每次将读取到的数据放到字节数组中
* 当读到文件末尾是在开始下一次循环
*/
while((length = input.read(b)) !=-1) {
String str = new String(b,0,length);
count++;
System.out.println(str);
}
System.out.println("count=" + count);
}
catch(FileNotFoundException ex) {
System.out.println("没有找到该文件" + ex.getMessage());
}
catch(IOException ex) {
System.out.println("文件读取异常" + ex.getMessage());
}
}
}
db.properties:
\u6570\u636E\u5E93\u8FDE\u63A5\u540D
\u6570\u636E\u5E93url
\u7528\u6237\u540D
\u5BC6\u7801
翻译;
数据库连接名
数据库url
用户名
密码
结果: