📄 casemixer.java
字号:
package examples.io;
import java.io.*;
import java.util.Random;
/** A class used to demonstrate file input and output
*/
public class CaseMixer {
/** Method randomly sets case of characters in a
* stream
* @param args[0] The name of the input file
* (defaults to standard in)
* @param args[1] The name of the output file
* (defaults to standard out)
* @throws IOException
* if a error is detected opening or closing the
* files
*/
public static void main( String[] args )
throws IOException {
InputStream istream;
OutputStream ostream;
if ( args.length >= 1 ) {
File inputFile = new File( args[0] );
istream = new FileInputStream( inputFile );
} else {
istream = System.in;
}
if ( args.length >= 2 ) {
File outputFile = new File( args[1] );
ostream = new FileOutputStream( outputFile );
} else {
ostream = System.out;
}
int c;
Random mixer = new Random();
try {
while ( ( c = istream.read() ) != -1 ) {
if ( mixer.nextFloat() < 0.5f ) {
c = Character.toLowerCase( (char) c );
} else {
c = Character.toUpperCase( (char) c );
}
ostream.write( c );
}
}
catch( IOException iox ) {
System.out.println( iox );
}
finally {
istream.close();
ostream.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -