android文件输出保存在虚拟机哪里

android文件输出保存在虚拟机哪里,第1张

android文件输出在虚拟机保存路径有以下几种。

1、StringFILE_PATH="/data/data/com.studio.android.ex/"。路径没错,但不是在开发Android应用的系统(Windows)上,而是在部署应用的Android设备上(或者模拟器里)。应该能在模拟器的界面里看到那些文件,或者是用adb在windows命令行来看也行。

2、运行输入adbshell(前提是模拟器正在运行)。

3、进入命令界面后输入ls指令会列出文件的目录。

4、cd进入你想要的目录里。

5、一层一层进去后会发现"/data/data/com.studio.android.ex/"目录下所创建的文件。查看txt文件内容使用cat命令。

可以,android的是基于java语言的你可以设置OutputStreamWriter的编码格式new java.io.OutputStreamWriter(out,"gb2312") 然后将输出流写到txt文件里就可以了

/**

* 保存文件

* @param toSaveString

* @param filePath

*/

public static void saveFile(String toSaveString, String filePath)

{

try

{

File saveFile = new File(filePath)

if (!saveFile.exists())

{

File dir = new File(saveFile.getParent())

dir.mkdirs()

saveFile.createNewFile()

}

FileOutputStream outStream = new FileOutputStream(saveFile)

outStream.write(toSaveString.getBytes())

outStream.close()

} catch (FileNotFoundException e)

{

e.printStackTrace()

} catch (IOException e)

{

e.printStackTrace()

}

}

/**

* 读取文件内容

* @param filePath

* @return 文件内容

*/

public static String readFile(String filePath)

{

String str = ""

try

{

File readFile = new File(filePath)

if(!readFile.exists())

{

return null

}

FileInputStream inStream = new FileInputStream(readFile)

ByteArrayOutputStream stream = new ByteArrayOutputStream()

byte[] buffer = new byte[1024]

int length = -1

while ((length = inStream.read(buffer)) != -1)

{

stream.write(buffer, 0, length)

}

str = stream.toString()

stream.close()

inStream.close()

return str

}

catch (FileNotFoundException e)

{

e.printStackTrace()

return null

}

catch (IOException e)

{

e.printStackTrace()

return null

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12009234.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存