Example usage for java.lang String endsWith

List of usage examples for java.lang String endsWith

Introduction

In this page you can find the example usage for java.lang String endsWith.

Prototype

public boolean endsWith(String suffix) 

Source Link

Document

Tests if this string ends with the specified suffix.

Usage

From source file:Main.java

public static void main(String[] arg) {

    String string1 = "abcde";
    if (string1.endsWith("de")) {
        System.out.println("ends with de");
    }//from  w ww. j  a va2  s.c o m
}

From source file:Main.java

public static void main(String[] args) {
    String strOrig = "Hello World";
    if (strOrig.endsWith("World")) {
        System.out.println("ends with World");
    } else {// ww w  .  j  ava  2 s .co  m
        System.out.println("not end with World");
    }
}

From source file:Main.java

public static void main(String[] args) {
    File directory = new File("c:\\");

    if (!directory.isDirectory()) {
        System.out.println("No directory provided");
        return;//from   ww w  .  ja  va2  s  .c om
    }

    FilenameFilter filefilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }
    };

    String[] filenames = directory.list(filefilter);

    for (String name : filenames) {
        System.out.println(name);
    }
}

From source file:Main.java

public static void main(String[] args) {
    File games = new File("C:\\Test");
    File[] files = games.listFiles();
    for (File file : files) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file"));
    }//from  ww  w. j a v a2 s.  c om
    String[] xfiles = games.list();
    for (String file : xfiles) {
        System.out.println("File = " + file);
    }
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".txt")) {
                return true;
            }
            return false;
        }
    };

    File[] yfiles = games.listFiles(filter);
    for (File doc : yfiles) {
        System.out.println("Doc file = " + doc);
    }
}

From source file:Main.java

public static void main(String[] argv) {
    String str = "java2s.com";
    String str2 = ".com";
    System.out.println(str.endsWith(str2));

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    String inName = args[0];
    String outName;//from   w w  w.j a v  a2  s  .  c  o m
    if (inName.endsWith(".pack.gz")) {
        outName = inName.substring(0, inName.length() - 8);
    } else if (inName.endsWith(".pack")) {
        outName = inName.substring(0, inName.length() - 5);
    } else {
        outName = inName + ".unpacked";
    }

    JarOutputStream out = null;
    InputStream in = null;

    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    out = new JarOutputStream(new FileOutputStream(outName));
    in = new FileInputStream(inName);
    if (inName.endsWith(".gz"))
        in = new GZIPInputStream(in);
    unpacker.unpack(in, out);
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String path = "C:/Pictures/";
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();
    DefaultListModel listModel = new DefaultListModel();
    int count = 0;
    for (int i = 0; i < listOfFiles.length; i++) {
        String name = listOfFiles[i].toString();
        if (name.endsWith("jpg")) {
            ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i]));
            listModel.add(count++, ii);/*from   w  w w .  jav a2 s . c o m*/
        }
    }
    JList lsm = new JList(listModel);
    lsm.setVisibleRowCount(1);

    frame.add(new JScrollPane(lsm));

    frame.pack();
    frame.setVisible(true);
}

From source file:com.graphhopper.tools.Bzip2.java

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        throw new IllegalArgumentException("You need to specify the bz2 file!");
    }/*from  ww  w.j a v  a2 s . c o  m*/

    String fromFile = args[0];
    if (!fromFile.endsWith(".bz2")) {
        throw new IllegalArgumentException("You need to specify a bz2 file! But was:" + fromFile);
    }
    String toFile = Helper.pruneFileEnd(fromFile);

    FileInputStream in = new FileInputStream(fromFile);
    FileOutputStream out = new FileOutputStream(toFile);
    BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
    try {
        final byte[] buffer = new byte[1024 * 8];
        int n = 0;
        while (-1 != (n = bzIn.read(buffer))) {
            out.write(buffer, 0, n);
        }
    } finally {
        out.close();
        bzIn.close();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String dirPath = "C:\\";
    File dir = new File(dirPath);

    // Create a file filter to exclude any .SYS file
    FileFilter filter = file -> {
        if (file.isFile()) {
            String fileName = file.getName().toLowerCase();
            if (fileName.endsWith(".sys")) {
                return false;
            }/*from   www .ja  v a  2 s. co m*/
        }
        return true;
    };

    File[] list = dir.listFiles(filter);

    for (File f : list) {
        if (f.isFile()) {
            System.out.println(f.getPath() + "  (File)");
        } else if (f.isDirectory()) {
            System.out.println(f.getPath() + "  (Directory)");
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    // Create a file filter to show only a directory or .doc files
    FileFilter filter = new FileFilter() {
        @Override/*from ww  w  .  j  av a 2s.  c  o  m*/
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String fileName = f.getName().toLowerCase();
            if (fileName.endsWith(".doc")) {
                return true;
            }

            return false; // Reject any other files
        }

        @Override
        public String getDescription() {
            return "Word Document";
        }
    };

    // Set the file filter
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(filter);

    int returnValue = fileChooser.showDialog(null, "Attach");
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        // Process the file
    }

}