Back to project page BusTicketer.
The source code is released under:
Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Red...
If you think the Android project BusTicketer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package bus.ticketer.utils; // w w w. j a va2s . c o m import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Date; import android.os.Environment; public class FileWriter { private String filename, username; private FileOutputStream fileOutStream; public FileWriter(String name) { this.filename = name; } public FileWriter(String name, String username) { this.filename = name; this.username = username; getFileStream(); } public void createFile() { String toWrite = "Ticket purchased in "; toWrite += new Date() + " by " + username + '\n'; try { fileOutStream.write(toWrite.getBytes()); } catch (IOException e) { e.printStackTrace(); } } public void writeToFile() { String toWrite = "Ticket validated in "; toWrite += new Date() + " by " + username + '\n'; try { fileOutStream.write(toWrite.getBytes()); } catch (IOException e) { e.printStackTrace(); } } public void getFileStream() { File directory = getAlbumStorageDir("BusTicketer"); File file = new File(directory, filename); fileOutStream = null; try { fileOutStream = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } } private File getAlbumStorageDir(String filename) { File file = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS), filename); if (!file.mkdirs()) { } return file; } }