java如何把字符串的内容保存到某位置的txt里?

来源:百度知道 编辑:UC知道 时间:2024/05/26 13:43:38
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Exam{
public static void main(String args[]) {
String input1 =JOptionPane.showInputDialog(null,
"请输入起始网页链接",
"老江说",
JOptionPane.QUESTION_MESSAGE);
String input2 =JOptionPane.showInputDialog(null,
"请输入目标网页链接",
"老江说",
JOptionPane.QUESTION_MESSAGE);
String input3 =JOptionPane.showInputDialog(null,
"请输入最大搜索长度",
"老江说",
JOptionPane.QUESTION_MESSAGE);
Scanner input = new Scanner(input1+"\n"+input2+"\n"+input3);
while (input.hasNext()) {
String a = input.next();
System.out.println(a);
}
input.close();

}
}

已经编写以上的东东,就是要把input1、input2、input3的内容保存到C盘目录下的link.txt里面。。。
需要加什么代码?
请详细写出,谢谢!
请详细写出,最好是那种可以复制粘贴直接用的那种

import java.io.FileOutputStream;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class Exam {
public static void main(String args[]) throws Exception {
String input1 = JOptionPane.showInputDialog(null, "请输入起始网页链接", "老江说",
JOptionPane.QUESTION_MESSAGE);
String input2 = JOptionPane.showInputDialog(null, "请输入目标网页链接", "老江说",
JOptionPane.QUESTION_MESSAGE);
String input3 = JOptionPane.showInputDialog(null, "请输入最大搜索长度", "老江说",
JOptionPane.QUESTION_MESSAGE);
Scanner input = new Scanner(input1 + "\n" + input2 + "\n" + input3);

FileOutputStream fos = new FileOutputStream("c:\\link.txt");
while (input.hasNext()) {
String a = input.next();
fos.write((a + "\r\n").getBytes());
}
fos.close();
input.close();
}