5
我正在写一个应用程序来在我的Nexus 5上创建一个文件夹,然后在该文件夹内写入一个文本文件。手机上的文件夹不显示在Windows PC
上面的部分工作得很好。我使用下面的代码书面方式:
创建的文件夹:
File sdCard1 = Environment.getExternalStorageDirectory();
File dir = new File(sdCard1.getAbsolutePath() + "/SmsApp");
if (dir.isDirectory())
{
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
{
new File(dir, children[i]).delete();
}
}
File sdCard = Environment.getExternalStorageDirectory();
directory = new File (sdCard.getAbsolutePath() + "/SmsApp");
directory.mkdirs();
和写入字符串文本文件。
public void writeToText(String texttosave)
{
File sdCard = Environment.getExternalStorageDirectory();
File logFile = new File(sdCard.getAbsolutePath() + "/SmsApp" + "/smsrawdata.file");
if (!logFile.exists())
{
try
{
logFile.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
try
{
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
buf.append(texttosave);
buf.newLine();
buf.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
文本文件是正确显示了我的手机上,但是当我试图访问手机上的同一个文件夹,我不能看到该文件夹的。
我认为它应该是相同的其他应用程序在创建一个文件夹,但然后创建一个文件夹,然后我可以看到他们在Windows资源管理器。
我在代码部分做错了什么,它不能显示在我的电脑上,只显示在我的手机上。我正在使用ES文件资源管理器查看手机上的文件。
请让我知道,如果别人有同样的问题。
谢谢!
您的计算机使用哪种协议来查看手机上的目录? – greenapps
这是使用MTP来查看文件 – TheDevMan
而你知道在哪里代表? – greenapps