InputStream - 图1

读取文件内容

  1. import java.io.FileInputStream;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. public class InputStreamTest {
  5. public static void main(String[] args) throws IOException {
  6. InputStream in = null;
  7. try{
  8. in = new FileInputStream(".\\src\\test.txt");
  9. StringBuilder sb = new StringBuilder();
  10. int n;
  11. while((n=in.read())!=-1){
  12. sb.append((char)n);
  13. }
  14. System.out.println(sb.toString());
  15. }finally {
  16. if(in != null) {
  17. in.close();
  18. }
  19. }
  20. }
  21. }