String (File file, int count) { String filePath = file.getPath(); if (count >= filePath.length()) return filePath; int nameLength = file.getName().length(); if (count <= nameLength) return filePath.substring(filePath.length() - count); int dotsCount = Math.min(3, count - nameLength); int shownCount = count - dotsCount; int leftCount = (shownCount - nameLength) / 2 + (shownCount - nameLength) % 2; int rightCount = shownCount - leftCount; return filePath.substring(0, leftCount) + dots(dotsCount) + filePath.substring(filePath.length() - rightCount); }