用JAVA语言编写程序:文件一的内容复制到文件二,并且复制过去后小写变成大写
答案:1 悬赏:80 手机版
解决时间 2021-02-20 11:28
- 提问者网友:流星是天使的眼泪
- 2021-02-20 05:32
用JAVA语言编写程序:文件一的内容复制到文件二,并且复制过去后小写变成大写
最佳答案
- 五星知识达人网友:不甚了了
- 2021-02-20 06:40
package test3;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile {
private static void copyAndConvert(String sourceFile, String destinyFile) throws IOException{
InputStream is = null;
OutputStream os = null;
int b;
try {
is = new FileInputStream(sourceFile);
os = new FileOutputStream(destinyFile);
while((b = is.read()) != -1){
if ((b >= 97) && (b <= 122)){ //a的ASCII码是97,z的ASCII码是122
b -= 32;
}
os.write(b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
os.close();
is.close();
}
}
public static void main(String[] args) throws IOException{
String sourceFile = "d:/book1.txt";
String destinyFile = "d:/book2.txt";
copyAndConvert(sourceFile, destinyFile);
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile {
private static void copyAndConvert(String sourceFile, String destinyFile) throws IOException{
InputStream is = null;
OutputStream os = null;
int b;
try {
is = new FileInputStream(sourceFile);
os = new FileOutputStream(destinyFile);
while((b = is.read()) != -1){
if ((b >= 97) && (b <= 122)){ //a的ASCII码是97,z的ASCII码是122
b -= 32;
}
os.write(b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
os.close();
is.close();
}
}
public static void main(String[] args) throws IOException{
String sourceFile = "d:/book1.txt";
String destinyFile = "d:/book2.txt";
copyAndConvert(sourceFile, destinyFile);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯