我有代码,我需要有一个主体和多种方法重构。人在那里,可以帮助一个非常简单的答案吗?
:8171645 |会员public class Quiz {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw = null;
String inputString = null;
String outputString = null;
// accept string from user
System.out.print("User input ");
try {
br = new BufferedReader(new InputStreamReader(System.in));
inputString = br.readLine();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(inputString);
// write string to disk file named data.dat
try {
bw = new BufferedWriter(new FileWriter("data.dat"));
bw.write(inputString);
bw.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// read the string back in from the file
try {
br = new BufferedReader(new FileReader("data.dat"));
inputString = br.readLine();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// display to the screen
System.out.println(inputString);
}// main
}// class