<pre name="code" class="java"> public static void writeFile(String str, String pathname) {
String path = Environment.getExternalStorageDirectory().getPath();
Log.i("glttest", "path:" + path);
File file = new File(path, pathname);
try {
if (!file.exists()) {
file.createNewFile();
}
long currentTimeMillis = System.currentTimeMillis();
Date d = new Date(currentTimeMillis);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = format.format(d);
RandomAccessFile random = new RandomAccessFile(file, "rw");
random.seek(random.length());
String s = time + "-----" + str + "\n";
random.writeUTF(s);
random.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
writeFile("ldasjlk", "log.txt");