package chap10.esc03;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Demo1 {
public static void main(String[] args) throws Exception {
File file=new File("G://JAVA在线学习//java测试临时文件.txt");
InputStream inputStream=new FileInputStream(file); //实例化FileInputStream
byte b[]=new byte[1024];
inputStream.read(b);
inputStream.close();//关闭输出流
System.out.println("读取的内容是:"+new String(b));
}
}
输出结果是:
读取的内容是:我在学java。
你在学吗!
然而,转化为UTF-8以后却出现乱码了?
System.out.println("读取的内容是:"+new String(b,"UTF-8"));
读取的内容是:?????java??
???????
希望大神能够答疑解惑!
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Demo1 {
public static void main(String[] args) throws Exception {
File file=new File("G://JAVA在线学习//java测试临时文件.txt");
InputStream inputStream=new FileInputStream(file); //实例化FileInputStream
byte b[]=new byte[1024];
inputStream.read(b);
inputStream.close();//关闭输出流
System.out.println("读取的内容是:"+new String(b));
}
}
输出结果是:
读取的内容是:我在学java。
你在学吗!
然而,转化为UTF-8以后却出现乱码了?
System.out.println("读取的内容是:"+new String(b,"UTF-8"));
读取的内容是:?????java??
???????
希望大神能够答疑解惑!