码迷,mamicode.com
首页 > 编程语言 > 详细

java——输入流FileInputStream

时间:2016-07-06 21:30:02      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

写一个简单的程序,实现从电脑中的一个盘里的文件中往程序中输入内容。

package com.liaojianya.chapter5;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * This program demonstrates Scanner class
 * @author LIAO JIANYA
 *
 */
public class ScannerTest2
{
	public static void main(String[] args) throws FileNotFoundException
	{
//		File file = new File("F:\\", "HelloWorld.txt");
//		FileInputStream in = new FileInputStream(file);
		FileInputStream in = new FileInputStream("F:\\HelloWorld.txt");
		Scanner s = new Scanner(in);
		while(s.hasNextLine())
		{
			System.out.println(s.nextLine());
		}
		s.close();
	}
	

}

在F盘写一个简单的txt文件如下  

技术分享

程序运行后:

结果显示:
public class HelloWorld
{
    public static void main(String[] args)
    {
	System.out.println("Hello world!");
    }

}

  

java——输入流FileInputStream

标签:

原文地址:http://www.cnblogs.com/Andya/p/5647987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!