Android删除concat或合并变量的变量内容

时间:2016-07-15 14:14:00

标签: java android

在下面的代码中为:

String marketUUid = "bc76b7a5-3166-11e6-b8fe-ec9a74f8851a";

String filePath = imagePath + "/" + marketUUid + "/" + "banners";
File   checkMarketBannerFolder = new File(filePath);

当我尝试将concat marketUUid与imagePath等其他变量合并并将其放到filePath时,将其从此操作中移除并且我没有该变量,这意味着之后合并变量my filePath

/storage/emulated/0/Signal/image/banners

但是这段代码没有任何问题:

String filePath = imagePath + "/" + "bc76b7a5-3166-11e6-b8fe-ec9a74f8851a" + "/" + "banners";

什么事发生?

1 个答案:

答案 0 :(得分:0)

格式化字符串有一种更简洁易读的方式:

String marketUUid = "bc76b7a5-3166-11e6-b8fe-ec9a74f8851a";
String imagePath = "image";

String filePath = String.format(
        "%s/%s/banners",
        imagePath,
        marketUUid
);