import java.io.*;
public class FileInputStreamTest {
public static void main(String[] args) throws IOException{
//声明流对象
FileInputStream fis=null;
try
{
// fis=new FileInputStream(FileDescriptor.in);
fis=new FileInputStream("D:\\myDoc\\hello.txt");
// InputStreamReader reader = new InputStreamReader(fis,"utf-8");
int data;
System.out.println("可读取的字节数:"+fis.available());
System.out.println("文件内容为:");
//循环读数据
byte[] cc=new byte[1024];//中转站数组
while((data=fis.read(cc))!=-1)
{
String c=new String(cc,0,data);//将byte转换为String类型
System.out.print(c+"");
}
}catch (FileNotFoundException e)
{
e.printStackTrace();
}catch (IOException e)
{
e.printStackTrace();
}finally {
try {
if (fis!=null)
{
fis.close();
}
}catch (IOException e)
{
e.printStackTrace();
}
}
}
}
I/O流使用字节流编译乱码如何解决
最新推荐文章于 2024-07-09 16:46:46 发布