zoukankan      html  css  js  c++  java
  • 第八周课程总结

    Java实验报告

    班级 计科二班 学号 20188450 姓名 李代传

    完成时间 2019.10.31

    评分等级

    课程总结

    本周无实验总结,只在课堂上布置了两个编程作业。

    如下:

    代码如下:

    package 输入输出流;

    import java.io.File;

    import java.io.FileNotFoundException;

    import java.io.FileReader;

    import java.io.FileWriter;

    import java.io.Reader;

    import java.io.Writer;

    import java.util.Scanner;

    public class Main {

        public static void main(String[] args) throws Exception {

            String pathname="C:"+File.separator+"Users"+File.separator+"ASUS"+File.separator+"Desktop"+File.separator+"java作业"+File.separator+"测试文件类"+File.separator+"新文件.txt";

            aFormatA(pathname);

        }

        public static void aFormatA(String pathname) throws Exception {

            File file=new File(pathname);

            Reader input=new FileReader(file);

            Writer out=new FileWriter(file,true);

            int c;

            out.write(' ');

            String str="字母大写";

            out.write(str);

            out.write(' ');

            while(true) {

                if((c=input.read())!=-1) {

                     if(c>=97&&c<=122) {

                        c=c-97+'A';

                     }

                     out.write(c);

                }else {

                    break;

             }

         }

            input.close();

            out.close();

        }

    }

    package 输入输出流;

    import java.io.File;

    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.io.FileOutputStream;

    import java.io.InputStream;

    import java.io.OutputStream;

    public class Main1 {

        public static void main(String[] args) throws Exception {

            String pathname="C:"+File.separator+"Users"+File.separator+"ASUS"+File.separator+"Desktop"+File.separator+"java作业"+File.separator+"测试文件类"+File.separator+"新文件.txt";

            aFormatA(pathname);

        }

        private static void aFormatA(String pathname) throws Exception {

            // TODO Auto-generated method stub

            File file =new File(pathname);

            InputStream input=new FileInputStream(file);

            OutputStream out=new FileOutputStream(file,true);

            byte[] b=new byte[(int)file.length()];

            int i=0;

            int c;

            while(true) {

                if((c=input.read())!=-1) {

                    if(c<=122&&c>=97) {

                        c=c-97+'A';

                    }

                    b[i]=(byte)c;

                    i++;

                }else {

                    break;

                }

            }

            out.write(" 字母大写 ".getBytes());

            out.write(b);

            input.close();

            out.close();

        }

    }

    以上代码实现的内容是读取文件中的字符,并把小写字符改变为大写,我把输出位置设在原文件中,没有输出在控制台了。(虽然代码不同,但是结果是一模一样的),老师说的可能是奇数位的小写改为大写,如果是这样的话,加一个标志位flag判断奇偶就行了。

    课程总结:

    还是要多自己实践,虽然上课的时候看代码看得懂,但是自己写就不一定能清晰思路写好代码了,而且自己写了才能对方法有自己的认识,才能知道方法怎么用。

    本周学习了各种输入输出流,如果觉得这各种流很混乱,了解不清晰的同学可以多看看javaAPI文档。没有的或者版本低可以自己去网上搜,然后下载,因为java更新快,所以有些API没有一些类。反正就是多看,然后自己写代码吧。写了才能知道方法怎么用,看了不一定会记得。

  • 相关阅读:
    jquery更改输入框type为密码框password
    用table做网页,设置了border为1px怎么还是觉得很粗?
    键盘按钮keyCode大全
    兼容firefox的 keyCode
    php生成随机字符串和验证码的类
    asp.net多图片上传实现程序代码
    asp.net图片上传实例
    纯js分页代码(简洁实用)
    jQuery中读取json文件示例代码
    perl编程中的map函数示例
  • 原文地址:https://www.cnblogs.com/xqldc/p/11772759.html
Copyright © 2011-2022 走看看