云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java语言实验6 常用类和输入输出流

Java语言实验6 常用类和输入输出流

  • 62 次阅读
  • 3 次下载
  • 2025/6/16 4:37:32

if ((month == 4) || (month == 6) || (month == 9) || (month == 11)){ return 30; } if (month == 2) return isLeapYear(year) ? 29:28; return 0;//如果月份错误 } public static boolean isLeapYear(int year) { // return true; return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } } 运行结果: 4、字符输入流和字符输出流 (1)内容 编写一个Java应用程序,将已存在的扩展名为.txt文本文件加密后存入另一个文本文件中。 (2) 源代码: package t4; import java.io.*; public class SecretExample { public static void main(String args[ ]) {

File fileOne=new File(\), fileTwo=new File(\); char b[]=new char[100]; try{ FileReader in=new FileReader(fileOne);//创建指向fileOne的字符输入流 FileWriter out=new FileWriter(fileTwo);//创建指向fileTwo字符输出流。 int n=-1; while((n=in.read(b))!=-1) { for(int i=0;i

运行结果: 5、缓冲流 (1)内容 编写一个Java应用程序,给已存在的txt文本文件添加行号。要求该文本文件事先用文本编辑完毕,保存在C:\\1000目录中,命名为hello.txt。 (2) 源代码: package t5; import java.io.*; public class ReadExample { public static void main(String args[ ]) {

File file=new File(\); File tempFile=new File(\); try{ FileReader inOne=new FileReader(file);// 创建指向文件file的输入流。 BufferedReader inTwo= new BufferedReader(inOne);// 创建指向inOne file的输入流。 FileWriter tofile=new FileWriter(tempFile);// 创建指向文件tempFile的输出流。 BufferedWriter out=new BufferedWriter(tofile);// 创建指向tofile的输出流。 String s=null; int i=0; s=inTwo.readLine();//inTwo读取一行。 while(s!=null) { i++; out.write(i+\+s); out.newLine(); s=inTwo.readLine();//inTwo读取一行。 } inOne.close(); inTwo.close(); out.flush(); out.close(); tofile.close(); inOne=new FileReader(tempFile);// 创建指向文件tempFile的输入流 inTwo= new BufferedReader(inOne);// 创建指向inOne file的输入流。 tofile=new FileWriter(file);// 创建指向文件file的输出流。 out=new BufferedWriter(tofile);// 创建指向tofile的输出流。 while((s=inTwo.readLine())!=null) ////inTwo读取一行。 { out.write(s); out.newLine(); } inOne.close(); inTwo.close(); out.flush(); out.close(); tofile.close(); inOne=new FileReader(file);// 创建指向文件file的输入流。 inTwo=new BufferedReader(inOne);// 创建指向inOne file的输入流。 while((s=inTwo.readLine())!=null) ////inTwo读取一行。 { System.out.println(s); } inOne.close();

搜索更多关于: Java语言实验6 常用类和输入输出流 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

if ((month == 4) || (month == 6) || (month == 9) || (month == 11)){ return 30; } if (month == 2) return isLeapYear(year) ? 29:28; return 0;//如果月份错误 } public static boolean isLeapYear(int year) { // return true; return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } } 运行结果: 4、字符输入流和字符输出流 (1)内容 编写一个Java应用程序,将已存在的扩展名为.txt文本文件加密后存入另一个文本文件中。 (2) 源代码: package t

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com