我真的需要帮助Java io操作Streams。我不知道为什么这不会告诉我文件的内容。我需要能够在这个二进制文件中查看文本" Data.abc"如果我可以查看该文件的内容,我需要创建一个switch case条件来显示每行/每列的内容。 每次我运行程序时,它会返回一些奇怪的字母和字符,如�NAme地址�����
请帮忙。我对流的操纵很新。谢谢。
package IO_ReadFile;
import java.io.*;
public class ReadFile {
public static void main(String[] args) {
InputStream istream; // creates an Input Stream and named it "istream"
OutputStream ostream; // creates an Output Stream and named it "ostream"
File inputFile = new File("Data.abc"); //passes file as argument
int c;
final int EOF=-1;
ostream = System.out;
try
{
istream = new FileInputStream(inputFile);
try
{
while((c=istream.read()) !=EOF)
ostream.write(c);
}
catch(IOException e)
{
System.out.println("Error: " + e.getMessage());
}
finally
{
try
{
istream.close();
ostream.close();
}
catch(IOException e)
{
System.out.println("File did not close");
}
}
}
catch(FileNotFoundException e)
{
System.exit(1);
}
}
}