如何将输入窗口的内容以文本形式保存到本地

allen0311 allen0311 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.util.HashSet;
public class SupportSystem{
private InputReader reader;
/**
* Creates a technical support system.
*/ public SupportSystem() {
reader = new InputReader(); }
/**
* Start the technical support system. This will print a welcome message and enter
* into a dialog with the user, until the user ends the dialog.
*/
public void start() {
boolean finished = false;
printWelcome();
while(!finished)
{
HashSet input = reader.getInput();
if(input.contains("bye"))
{
finished = true;
}
else
{
System.out.println("response");
}
}
printGoodbye();
}

/**
* Print a welcome message to the screen.
*/

private void printWelcome()
{
System.out.println("Welcome to the DodgySoft Technical SupportSystem.");
System.out.println();
System.out.println("Please tell us about your problem.");
System.out.println("We will assist you with any problem you might have."); System.out.println("Please type 'bye' to exit our system.");
}

/**
* Print a good-bye message to the screen.
*/

private void printGoodbye()
{
System.out.println("Nice talking to you. Bye...");
}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Arrays;

public class InputReader
{
private BufferedReader reader;
/**
* Create a new InputReader that reads text from the text terminal.
*/

public InputReader()
{ reader = new BufferedReader(new InputStreamReader(System.in));; }

/**
* Read a line of text from standard input (the text
* terminal), and return it as a set of words.
*
* @return A set of Strings, where each String is one of the
* words typed by the user
*/
public HashSet getInput()

{ System.out.print("> "); // print prompt
String inputLine = readInputLine().trim().toLowerCase();
String[] wordArray = inputLine.split(" "); // split at spaces
// add words from array into hashset
HashSet words = new HashSet();
for(int i=0; i < wordArray.length; i++)
{ words.add(wordArray[i]);
}
return words;
}


/**
* Read one line of input and return it as a String.
*
* @return A String representing the input, or an empty String
* if an error occurs.
*/

private String readInputLine()
{ String line = "";
try { line = reader.readLine();
}
catch(java.io.IOException exc)
{ System.out.println ("Read error: " + exc.getMessage());
}
return line;
}
}


请问 在执行了 class SupportSystem 里面的method start 以后, 怎么把输入的对话用
filewriter 存入文本啊

我知道可以这样
BufferedWriter bufOut=new BufferedWriter(new FileWriter(FilePath));
bufOut.write("your Strings");
bufOut.flush();

但是如何从对话中把"your Strings"的值获取出来
...全文
评论 3
收藏 已收藏
分享
返回顶部
allen0311
Java SE 62,621 成员 307,251 内容