您的位置:首页 > 编程语言 > Java开发

java重定向标准输入输出

2016-10-20 11:00 302 查看
重定向stdin stdout,方便读文件.

public class Test {
public static void main(String[] args) throws IOException {
FileInputStream fis=new FileInputStream("红包雨白名单账户.txt");
System.setIn(fis);
PrintStream ps=new PrintStream(new FileOutputStream("红包雨白名单账户.sql"));
System.setOut(ps);
Scanner sc=new Scanner(System.in);
int count = 0;
while(sc.hasNextLine()) {
String str = sc.nextLine();
if(str == null || str.length() == 0) continue;
count++;
System.out.println("insert into mapi_redbag_rain_white_roll (user_id, is_enabled, create_time) values('" + str + "', 'Y', now());");
}
System.out.println("一共有" + count + "个账户");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: