【发布时间】:2015-01-31 15:14:56
【问题描述】:
我正在尝试使用字节流读取包含普通文本数据的文件。而且我知道在字节流中每个字节都会被一个一个地读取。因此,如果我通过字节流读取文本文件中的数据Hi How are you!!!!!!,那么它应该给我每个字符的 Unicode 等价物,但它会给我一个不同的输出,它不会映射到 utf 或 ascii 等价物。
下面是我的程序
package files;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class FileBaiscs {
public static void main(String[] args) throws IOException {
String strPath = "D:\\Files\\New.txt";
File objSrcFile = new File (strPath);
if (objSrcFile.exists()==false)
{
System.out.println("The Source File is not Present");
System.exit(0);
}
FileInputStream objIpStream = new FileInputStream(objSrcFile);
while ((objIpStream.read())!=-1)
{
System.out.println(objIpStream.read());
}
objIpStream.close();
}
}
我的控制台中的输出是:
105
72
119
97
101
121
117
33
33
33
新文本文件中的数据是-Hi How are you!!!!!!
我希望输出是整数,它相当于每个字符的 utf。如果我的理解有误,请告诉我。
【问题讨论】:
标签: java