如何在其他应用程序可以看到的公共存储中写入文本文件。即文件管理器。 我的代码有什么问题。
String filename = "kontaktebi123.vcf";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
PrintWriter osw = new PrintWriter(outputStream);
ArrayList<String> nomrebi = numberGenerator(view);
osw.printf("blablabla")
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:2)
您必须将文件写入Document
,Download
等公共目录中。
String fileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
String fileName = "kontaktebi123.vcf";
File file = new File(fileDir + "/" + fileName);
现在写入文件,其他应用将可以看到该文件。
答案 1 :(得分:0)
try{
FileOutputStream fileOutStream = openFileOutput(fileName.txt",MODE_PRIVATE);
OutputStreamWriter outputWriter = new OutputStreamWriter(fileOutStream);
outputWriter.write("write your text here");
outputWriter.close();
Toast.maketext(context,"File Saved Successfully",Toast.LENGTH_SHORT).show();
}catch(Exception e){
e.printStackTrace();
}