public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double d;
File file = new File("report.txt");
FileWriter fw = null;
if (!file.exists()) {
file.createNewFile();
}
System.out.print("输入一个double型变量的值:");
d = scanner.nextDouble();
try {
fw = new FileWriter(file, true);
fw.write("double变量:" + String.valueOf(d));
fw.write("\n");
fw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double d;
File file = new File("report.txt");
FileWriter fw = null;
if (!file.exists()) {
file.createNewFile();
}
System.out.print("输入一个double型变量的值:");
d = scanner.nextDouble();
try {
fw = new FileWriter(file, true);
fw.write("double变量:" + String.valueOf(d));
fw.write("\n");
fw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}