Package elwin. fei. mobileaudio;
Import java. io. BufferedWriter;
Import java. io. File;
Import java. io. FileWriter;
Import java. io. IOException;
Import java. text. SimpleDateFormat;
Public class CreateFiles {
String filenameTemp = Info. audioPath + "/hhaudio" + ". txt ";
// Create folders and files
Public void CreateText () throws IOException {
File file = new File (Info. audioPath );
If (! File. exists ()){
Try {
// Create a folder Based on the specified path
File. mkdirs ();
} Catch (Exception e ){
// TODO: handle exception
}
}
File dir = new File (filenameTemp );
If (! Dir. exists ()){
Try {
// Create a file in the specified folder
Dir. createNewFile ();
} Catch (Exception e ){
}
}
}
// Write data to the created File
Public void print (String str ){
FileWriter fw = null;
BufferedWriter bw = null;
String datetime = "";
Try {
SimpleDateFormat tempDate = new SimpleDateFormat ("yyyy-MM-dd" + ""
+ "Hh: mm: ss ");
Datetime = tempDate. format (new java. util. Date (). toString ();
Fw = new FileWriter (filenameTemp, true );//
// Create a FileWriter object to write data to the volume stream.
Bw = new BufferedWriter (fw); // buffer the output of the file
String myreadline = datetime + "[]" + str;
Bw. write (myreadline + "\ n"); // write the file
Bw. newLine ();
Bw. flush (); // refresh the buffer of the stream
Bw. close ();
Fw. close ();
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
Try {
Bw. close ();
Fw. close ();
} Catch (IOException e1 ){
// TODO Auto-generated catch block
}
}
}
}
From Feige's column