Java String Abbreviate abbreviateFileName(final String fileName)

Here you can find the source of abbreviateFileName(final String fileName)

Description

Create a truncated file name suitable for display in interfaces

License

BSD License

Parameter

Parameter Description
fileName a parameter

Declaration

public static final String abbreviateFileName(final String fileName) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**//from   ww  w .j av  a  2  s  . co m
     * Create a truncated file name suitable for display in interfaces
     *
     * @param fileName
     * @return
     */
    public static final String abbreviateFileName(final String fileName) {

        if (fileName == null) {
            throw new IllegalArgumentException("null fileName");
        }

        StringBuilder sb = new StringBuilder();
        if (fileName.length() < 100) {
            sb.append(fileName);
        } else {
            // gt 100 bytes, redact
            sb.append(fileName.substring(0, 50));
            sb.append(" ... ");
            sb.append(fileName.substring(fileName.length() - 50));
        }

        return sb.toString();

    }
}

Related

  1. abbreviate(String text, int maxFront, int maxBack)
  2. abbreviate(String text, Number maxNbrChars)
  3. abbreviate(String time)
  4. abbreviated(final String str, final int maxLength)
  5. abbreviateDotSeparatedString(String string, int targetLength)
  6. abbreviateInCenter(String stringToAbbreviate, int length)
  7. abbreviateLeft(String s, int width)
  8. abbreviateMessage(String messageBody)
  9. abbreviateMiddle(String str, String middle, int length)