android - Want to create a file, a directory created instead ! -
i'm using code create file in root of sdcard, however, have directory created instead of "filedir+filename" !
file file = new file(sdcard.getabsolutepath(), filedir+filename); if (!file.mkdirs()) { log.d("error", "create dir in sdcard failed"); return; } outputstream out = new fileoutputstream(file); .............................. thank help.
file.mkdirs() creates directory , not file [ref: http://download.oracle.com/javase/1.4.2/docs/api/java/io/file.html#mkdir(). code creates directory. should use code this.
string destination = currentdir + "test.txt"; file filecon = new file(destination); if( ! filecon.exists() ){ filecon.createnewfile(); } alternatively try this,
string destination = currentdir + "test.txt"; // open output stream fileoutputstream fout = new fileoutputstream(destination); fout.write("test".getbytes()); // close output stream fout.flush(); fout.close();
Comments
Post a Comment