import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/*
* 创建时间:14-4-20 上午10:00
* 设计人员:dongxl.
*/
public class InputStreamTest {
public static void main(String[] args) {
try {
int counts = 0;
int all = 0;
InputStream inputStream = new FileInputStream("D:/a.txt");
try {
all = inputStream.available();
System.out.println(all);
} catch (IOException e) {
e.printStackTrace();
}
byte[] bytes = new byte[all];
// byte[] bytes = new byte["hello world.".length()];
char[] chars = new char[all];
// char[] chars = new char["hello world.".length()];
try {
counts = inputStream.read(bytes);
String str = new String(bytes);
System.out.println(str);
for (int i = 0; i < bytes.length; i++) {
chars[i] = (char)bytes[i];
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(chars);
System.out.println(counts);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
FileStreamTest
最新推荐文章于 2020-04-11 09:31:02 发布