java记事本代码另存为
时间: 2024-01-02 07:41:54 浏览: 76
您好!感谢您对ChitGPT的使用。关于您的问题,以下是Java记事本另存为的代码示例:
```
import java.io.*;
public class SaveAs {
public static void main(String[] args) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String input = bufferedReader.readLine();
FileWriter fileWriter = new FileWriter(input);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
String content = bufferedReader.readLine();
bufferedWriter.write(content);
bufferedWriter.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
```
您可以将代码保存为SaveAs.java文件,然后在命令行中执行以下命令来编译并运行代码:
```
javac SaveAs.java
java SaveAs
```
如有其他问题,欢迎继续咨询我!
阅读全文