public void writeToFile(String n) {
//Deklaration
FileWriter pw = null;
try {
//Skapa en StringBuffer
StringBuffer buf = new StringBuffer();
// Lägg till det som ska in i filen.
buf.append(n).append(" ").append("\r\n");
//Öppna filen
File outFile = new File("Transaction.txt");
JOptionPane.showMessageDialog(null, "Filen sparad som Transaction.txt");
//Finns filen?
if (!outFile.exists()) {
outFile.createNewFile();
}
//Skriv sist i filen
pw = new FileWriter(outFile, true);
pw.write(buf.toString());
} catch (Exception e) {
System.err.print("Gick ej öppna. Avslutar");
System.exit(-1);
} //end catch
finally {
//Stäng filen
if (pw != null) {
try {
pw.flush();
pw.close();
} catch (IOException e) {
System.err.print("Gick ej stänga filen. Avslutar");
System.exit(-1);
} //end catch
} //end if
} //end finnaly
} //end writeToFile
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE