最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】android中如何拼接路径

Android crifan 6024浏览 0评论

【背景】

折腾:

【已解决】android项目中代码中如何获得对应的项目名

期间,需要去拼接路径。

【折腾过程】

1.看了一堆,参考:

Does Java have a path joining method? [duplicate]

去试试:

		String extSdRootPath = Environment.getExternalStorageDirectory();
		String logFolderName = Start.getContext().getPackageName();
		String logFolderPath = new File(extSdRootPath, logFolderName).toString();

结果出错:

extSdRootPath是String,但是要求是File才行。

2.结果是:

public static String combinePath(String path1, String path2)
{
    File file1 = new File(path1);
    File file2 = new File(file1, path2);
    return file2.getPath();
}

String extSdRootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
String logFolderPath = CommonLib.combinePath(extSdRootPath, logFolderName);
String logFullfilename = CommonLib.combinePath(logFolderPath, logFilename);

也是使用。

 

【总结】

还是java中的库函数太挫。搞得还得自己写基本的常用的函数。。。哎。。。

转载请注明:在路上 » 【已解决】android中如何拼接路径

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.165 seconds, using 22.13MB memory