
程序设计急急急啊 四十分钟内 向文本文件in.dat中写入一行文本,使得输入 Hello World! 输出 HELLO WORLD!
展开全部
//Java实现
package com.tst;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException {
FileInputStream fis;
FileOutputStream fos;
String filePath = "D:\\in.dat";
try {
fos = new FileOutputStream(filePath);
fos.write(String.valueOf("Hello World").getBytes());
fos.flush();
fos.close();
fis = new FileInputStream(filePath);
byte[] b = new byte[fis.available()];
fis.read(b);
String bString = new String(b);
System.out.println(bString.toUpperCase());
System.out.println("success");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.tst;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException {
FileInputStream fis;
FileOutputStream fos;
String filePath = "D:\\in.dat";
try {
fos = new FileOutputStream(filePath);
fos.write(String.valueOf("Hello World").getBytes());
fos.flush();
fos.close();
fis = new FileInputStream(filePath);
byte[] b = new byte[fis.available()];
fis.read(b);
String bString = new String(b);
System.out.println(bString.toUpperCase());
System.out.println("success");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
更多追问追答
追问
抱歉啊,你的答案不对啊,能不能修改啊
追答
怎么不对了,我执行后才回答的,你把字符串后边加上!就行了,最后的输出“success”只不过是提示成功而已
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询