⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replace.java

📁 北大Java 语言程序设计 ppt课件及源码
💻 JAVA
字号:
class Replace {    public static void Usage() {        System.out.println("\nUsage:  java Replace char1 char2 inFile outFile");    }    public static void main(String[] args) {        InputFile         in = null;       OutputFile        out = null;             char     former = 'A';             char     latter = 'A';           byte[]        buf;        try {               former = args[0].charAt(0);        } catch (ArrayIndexOutOfBoundsException e) {            Usage();            System.err.println("you must supply the character to replace\n");            System.exit(-1);        }        try {               latter = args[1].charAt(0);        } catch (ArrayIndexOutOfBoundsException e) {            Usage();            System.err.println("you must supply the new character\n");            System.exit(-1);        }        try {            in = new InputFile(args[2]);        } catch (ArrayIndexOutOfBoundsException e) {            Usage();            System.err.println("you must supply the input replacement file\n");            System.exit(-1);        }        try {            out = new OutputFile(args[3]);        } catch (ArrayIndexOutOfBoundsException e) {            Usage();            System.err.println("you must supply the output replacement file\n");            System.exit(-1);        }        System.out.println("Replacing "+args[0]+" with "+args[1]+" from "+                           args[2]+" to "+args[3]);        if (in.open() == false) {            System.out.println("Unable to open input file "+in.getFileName());        }        if (out.open() == false) {            System.out.println("Unable to open output file "+out.getFileName());        }        buf = new byte[1];        while (in.read(buf, 1) == 1) {            if (buf[0] == former)                buf[0] = (byte)latter;            if (out.write(buf, 1) != 1) {                System.out.println("Error writing to "+out.getFileName());            }        }         in.close();         out.close();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -