package demo;
import java.io.*;
public class TestWriter{
//先创建一个文件
public void createFile()throws Exception{
File file = new File("c.txt");
file.createNewFile();
}
public void testWriter()throws Exception{
FileOutputStream fos = new FileOutputStream("d:/se1004/day16/c.txt");
OutputStreamWriter ow = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(ow);
bw.write("你好,中国!");
bw.close();
}
public void testRead() throws Exception{
FileInputStream fis = new FileInputStream("d:/se1004/day16/c.txt");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
System.out.println(br.readLine());
br.close();
}
//写入多行内容到文件
public void testWriter2()throws Exception{
FileOutputStream fos = new FileOutputStream("d:/se1004/day16/cc.txt");
OutputStreamWriter out = new OutputStreamWriter(fos);
out.write("你好\r\n");
out.write("哈哈\r\n");
out.write("谢谢\r\n");
out.close();
}
public void testWriter3()throws Exception{
FileOutputStream fos = new FileOutputStream("d:/se1004/day16/cc.txt");
OutputStreamWriter out = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(out);
bw.write("你好");
bw.newLine();//换行的方法
bw.write("哈哈");
bw.newLine();
bw.write("谢谢");
bw.newLine();
bw.close();
}
public void testReader2()throws Exception{
FileInputStream fis = new FileInputStream("d:/se1004/day16/cc.txt");
InputStreamReader ir = new InputStreamReader(fis);
String str = "";
int tag = 0;
while((tag = ir.read()) != -1){
str += String.valueOf((char)tag);
if(tag == 10){
System.out.println(str);
str = "";
}
}
}
public void testReader3()throws Exception{
FileInputStream fis = new FileInputStream("d:/se1004/day16/cc.txt");
InputStreamReader ir = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(ir);
String line = br.readLine();
while(line != null){
System.out.println(line);
line = br.readLine();
}
}
public static void main(String[] args)throws Exception{
TestWriter t = new TestWriter();
//t.testWriter();
t.testReader2();
}
}
分享到:
相关推荐
Office 2007并不会像Office 2003那样自动安装虚拟打印机Microsoft Office Document Image Writer,而是自动安装了另一款虚拟打印机Microsoft XPS Document Writer,难道Office 2007不支持Microsoft Office Document ...
Microsoft XPS Document Writer 即:XPS虚拟打印机 软件开发打印测试的必备工具。 突然发现不能用了,缺少驱动什么的,删除了,没法再安装了。网上找了半天,得解,有人竟然要8分,做人要厚道,我只要1分。 适用...
windows live writer 插件,代码插件,文字竖排插件,表情插件
StyleWriter - the World's Largest Style and Usage checker - is the world's most powerful editor. It plugs directly into all versions of Microsoft Word. 有Microsoft word插件,写作和语法修改同时进行。 ...
ImageWriter 非常小巧好用的USB启动盘制作工具 解压即用 完美解决报错 给有需要的人
Win7在安装后在控制面板里面的打印机就会自动生产“Microsoft XPS Document Writer虚拟机”,XP系统安装后没有“Microsoft XPS Document Writer虚拟机”但是为什么Office办公软件安装完后没有“Microsoft Office ...
IMEI号烧写步骤SN_Writer_tool 描述使用安卓设备烧入IMEI号的步骤文档
Pattern_Writer
CutePDF Writer 提供方便的 PDF 印制功能,无论你正在看是网页或者各式文件,只要能以打印机打印出来的,CutePDF Writer 都能将它们「印成」PDF 格式,方便文件档案在各式计算机平台上阅览。
mpeg4 writer ffmpeg.
windows live writer 2016,微软开源的最新writer软件
而最近遇到的一款国产跨平台的 MD 文本编辑器新秀—— Yu Writer,又给我们带来了不一样的感受! Yu Writer 是一款值得推荐的国产 Markdown 文本编辑器新秀!它跨平台支持 Win、macOS、Linux 甚至是树莓派。拥有精美...
xmlwriter中文版xmlwriter中文版xmlwriter中文版
XMLwriter有一个直观性、个性化的用户界面让使用者编辑,还具有书签功能,自动查找并替代。其他的功能还有 XML在线帮助、插件管理、即时色彩编码转换、树型结构查看、批量及命令行处理、可扩充的能力及更多开发功能...
stylewriter 大名鼎鼎,不用多说了。
WhiteSmoke Writer 2011英文写作纠错软件
xmlwriter有汉化补丁
Yu Writer:一款能找到写作乐趣的 Markdown 文本编辑器,致力为你营造一个舒适、专注、高效的写作环境。网址:https://ivarptr.github.io/yu-writer.site/
SONIX 8/32-bit MCU烧录器MP PRO Writer使用前要和电脑连接起来。使用SONIX松翰单片机烧录工具前请注意下面几点:1. 本软件仅支援MP PRO Writer!2. 本软件只支援SONIX烧录文件!3. 40 Pin及以下的MCU无需...
BirdA SN Writer 3.4 通用.rar 通用写号工具非常好用