[Java] 将标准字符流写入到文件中(通过控制台写一个html程序,并保存)
2024-08-26 22:45:30
package test.stream; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter; /**
* 通过控制台写一个html程序,并输出
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @date 2016年4月13日
*/
public class TestHtml {
public static void main(String[] args) {
BufferedReader br = null;
PrintWriter out = null;
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new BufferedWriter(new FileWriter("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\test.html")));
String str = null;
while((str = br.readLine())!=null){
if (str.equals("exit")) {
System.out.println("thank you");
break;
}
out.println(str);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(br!=null) br.close();
} catch (IOException e) {
e.printStackTrace();
} try {
if(out!=null) out.close();
} catch (Exception e) {
e.printStackTrace();
}
} }
}
运行后在控制台输入
<html>
<head><title>java test</title></head>
<body>
<marquee><h1>notic java do it<h1><marquee>
</body>
<html>
exit
回车
即可生成test.html
最新文章
- gitlab使用个人版v16.11
- C#语言实现定时开启或禁用网卡小程序
- 我的第二个FluentNHibernate例子with Knockout
- 优化与扩展Mybatis的SqlMapper解析
- BZOJ2049——[Sdoi2008]Cave 洞穴勘测
- Android动画translate坐标图
- LCS(打印路径) POJ 2250 Compromise
- 高并发网络编程之epoll详解
- 如何使用ZBLibrary-Android快速开发框架
- java连接oracle数据库的实现代码
- [Android] 输入系统(二)
- BuildSigar
- git使用系列(一)
- 关键字final的用法
- Leetcode_122_Best Time to Buy and Sell Stock II
- .netcore2.0发送邮件
- blfs(systemv版本)学习笔记-配置远程访问和管理lfs系统
- C# CheckBox与RadioButton
- SysTick Software Timer
- 腾讯云服务器 Centos6.5 安装 nginx1.12.0
热门文章
- ctf之加密
- _appstart.cshtml,_pagestart.cshtml,_viewstart.cshtml
- ManifoldJS
- datatables的Bootstrap样式的分页怎么添加首页和尾页(引)
- python compile
- C# 输出pdf文件流在页面上显示
- 转:在ElasticSearch之下(图解搜索的故事)
- MS CRM 2011的自定义和开发(11)——插件(plugin)开发(四)
- openssl与cryptoAPI交互AES加密解密
- 最小生成树算法(Prim,Kruskal)