I'm trying to create a rudimentary history system for a web browser I'm designing, unfortunately, I can only find ways to either store 1 web address for a history, or not at all, the fileWriter and fileOutputStream seem to limit to one single item per write, which would overwrite the previous if I tried to output one at a time.
I would appreciate it if people could either suggest ways to store an entire list of strings in an external txt doc, bonus points if you can retain an order to them
request for code:
private void loadWebPage(String userInput) {
if (stackTest == true) {
forwardStack.push(urlBox.getText());
stackTest = false;
} else {
backStack.push(urlBox.getText());
}
try {
createHistory(urlBox.getText());
// displays the content of a html link in the web window, as per
// user input
webWindow.setPage(userInput);
// sets the text in the urlbox to the user input so they can check
// at any time what page they are on
urlBox.setText(userInput);
} catch (Exception e) {
// if user enters a bad url then produce error
try {
File file = new File(userInput);
webWindow.setPage(file.toURI().toURL());
} catch (Exception e1) {
System.out.println("Error 001: Bad URL");
}
}
}
private void createHistory(String webAddress) {
JMenuItem button = new JMenuItem(webAddress);
history.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent histPress) {
loadWebPage(webAddress);
historyStack.push(webAddress);
try {
FileWriter writer = new FileWriter(histPath, false);
writer.write(historyStack);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void recoverHistory() {
//this will read from the txt doc and create a
//history based on past uses of the browser
}
FileWriter will not store any data construct and will overwrite each value if done using string and forLoop
I hope someone knows the answer
Aucun commentaire:
Enregistrer un commentaire