Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

In this page you can find the example usage for java.io File getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:cz.certicon.routing.web.Application.java

/**
 * @param args the command line arguments
 *///from   w  w  w  . j a  va 2s  . c o m
public static void main(String[] args) {
    String filePath = "C:\\Routing\\Data\\CZ";
    if (args.length > 0) {
        filePath = args[0];
    }
    File file = new File(filePath);
    Settings.GRAPH_FILE_PATH = file.getAbsolutePath() + File.separator + file.getName() + ".graph.xml";
    Settings.COORDINATES_FILE_PATH = file.getAbsolutePath() + File.separator + file.getName() + ".coords.xml";
    SpringApplication.run(Application.class, args);
}

From source file:com.manning.blogapps.chapter10.examples.AuthPost.java

public static void main(String[] args) throws Exception {
    if (args.length < 4) {
        System.out.println("USAGE: authpost <username> <password> <filepath> <url>");
        System.exit(-1);// ww  w  . j  a v  a 2s.c  om
    }
    String credentials = args[0] + ":" + args[1];
    String filepath = args[2];
    String url = args[3];

    HttpClient httpClient = new HttpClient();
    EntityEnclosingMethod method = new PostMethod(url);
    method.setRequestHeader("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    File upload = new File(filepath);
    method.setRequestHeader("Title", upload.getName());
    method.setRequestBody(new FileInputStream(upload));

    String contentType = "application/atom+xml; charset=utf8";
    if (filepath.endsWith(".gif"))
        contentType = "image/gif";
    else if (filepath.endsWith(".jpg"))
        contentType = "image/jpg";
    method.setRequestHeader("Content-type", contentType);

    httpClient.executeMethod(method);
    System.out.println(method.getResponseBodyAsString());
}

From source file:com.manning.blogapps.chapter10.examples.AuthPut.java

public static void main(String[] args) throws Exception {
    if (args.length < 4) {
        System.out.println("USAGE: authput <username> <password> <filepath> <url>");
        System.exit(-1);//from  w  ww . j av  a  2s  .  c  o  m
    }
    String credentials = args[0] + ":" + args[1];
    String filepath = args[2];
    String url = args[3];

    HttpClient httpClient = new HttpClient();
    EntityEnclosingMethod method = new PutMethod(url);
    method.setRequestHeader("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    File upload = new File(filepath);
    method.setRequestHeader("name", upload.getName());

    String contentType = "application/atom+xml; charset=utf8";
    if (filepath.endsWith(".gif"))
        contentType = "image/gif";
    else if (filepath.endsWith(".jpg"))
        contentType = "image/jpg";
    method.setRequestHeader("Content-type", contentType);

    method.setRequestBody(new FileInputStream(filepath));
    httpClient.executeMethod(method);

    System.out.println(method.getResponseBodyAsString());
}

From source file:ddf.metrics.reporting.internal.rrd4j.SampleDataGenerator.java

public static void main(String[] args) {
    if (args.length == 1) {
        try {/*from   w  w w .  j  a v  a 2  s.  com*/
            String installLoc = args[0];
            File metricsDir = new File(installLoc, "/data/metrics");
            File[] files = metricsDir.listFiles();
            if (files != null) {
                for (File metricsFile : files) {
                    String metricsFileName = metricsFile.getName();
                    if (!metricsFileName.endsWith(".rrd")) {
                        continue;
                    }
                    RrdDb oldDb = new RrdDb(metricsFile.getAbsolutePath());
                    if (oldDb.getDsCount() > 1) {
                        continue;
                    }
                    DsType dsType = oldDb.getDatasource(0).getType();
                    String newDb = "target/" + metricsFileName;
                    long startTime = new DateTime().minusYears(1).getMillis();
                    int sampleSize = (int) ((new DateTime().getMillis() - startTime) / (60 * 1000));
                    new RrdMetricsRetrieverTest.RrdFileBuilder().rrdFileName(newDb).dsType(dsType)
                            .numSamples(sampleSize).numRows(sampleSize).startTime(startTime).build();
                    FileUtils.copyFile(new File(newDb), metricsFile);
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    exit(0);
}

From source file:JFileChooserSelectionOption.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("canceled");
    }//from   w w  w .j  a  va 2s. co m
}

From source file:com.github.rinde.gpem17.Train.java

public static void main(String[] args) {
    if (args.length == 0) {
        run("files/config/gpem17.params");
    } else {/*from   w  w  w  . j  av  a2  s .  c o  m*/
        for (String file : args) {
            File f = new File(file);
            if (f.isDirectory()) {
                File[] paramFiles = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".params");
                    }
                });

                Arrays.sort(paramFiles, new Comparator<File>() {
                    @Override
                    public int compare(File o1, File o2) {
                        return o1.getName().compareTo(o2.getName());
                    }
                });

                for (File paramFile : paramFiles) {
                    run(paramFile.getPath());
                }
            } else {
                run(file);
            }
        }
    }
}

From source file:FTPConnect.FTPSubirArchivo.java

public static void main(String[] args) throws IOException {
    FTPClient ftpclient = new FTPClient();
    FileInputStream fis = null;/*from w  w  w. j a v  a  2 s . c  o m*/
    boolean result;
    String ftpServerAddress = "localhost";
    String userName = "admin";
    String password = "admin";

    try {
        ftpclient.connect(ftpServerAddress);
        result = ftpclient.login(userName, password);

        if (result == true) {
            System.out.println("Logged in Successfully !");
        } else {
            System.out.println("Login Fail!");
            return;
        }
        ftpclient.setFileType(FTP.BINARY_FILE_TYPE);

        ftpclient.changeWorkingDirectory("/");

        File file = new File("D:/File.doc");
        String testName = file.getName();
        fis = new FileInputStream(file);

        // Upload file to the ftp server
        result = ftpclient.storeFile(testName, fis);

        if (result == true) {
            System.out.println("File is uploaded successfully");
        } else {
            System.out.println("File uploading failed");
        }
        ftpclient.logout();
    } catch (FTPConnectionClosedException e) {
        e.printStackTrace();
    } finally {
        try {
            ftpclient.disconnect();
        } catch (FTPConnectionClosedException e) {
            System.out.println(e);
        }
    }
}

From source file:ftp_server.FTPFileUpload.java

public static void main(String[] args) throws IOException {
    FTPClient ftpclient = new FTPClient();
    FileInputStream fis = null;/*ww w .ja  va  2s .  c  o m*/
    boolean result;
    String ftpServerAddress = "shamalmahesh.net78.net";
    String userName = "a9959679";
    String password = "9P3IckDo";

    try {
        ftpclient.connect(ftpServerAddress);
        result = ftpclient.login(userName, password);

        if (result == true) {
            System.out.println("Logged in Successfully !");
        } else {
            System.out.println("Login Fail!");
            return;
        }
        ftpclient.enterLocalPassiveMode();
        ftpclient.setFileType(FTP.BINARY_FILE_TYPE);

        ftpclient.changeWorkingDirectory("/public_html/testing");

        File file = new File("D:/jpg/wq.jpg");
        String testName = file.getName();
        fis = new FileInputStream(file);

        // Upload file to the ftp server
        result = ftpclient.storeFile(testName, fis);

        if (result == true) {
            System.out.println("File is uploaded successfully");
        } else {
            System.out.println("File uploading failed");
        }
        ftpclient.logout();
    } catch (FTPConnectionClosedException e) {
        e.printStackTrace();
    } finally {
        try {
            ftpclient.disconnect();
        } catch (FTPConnectionClosedException e) {
            System.out.println(e);
        }
    }
}

From source file:com.smartling.api.sdk.file.commandline.RetrieveFile.java

/**
 * @param args The arguments to pass in.
 * <pre>//from w  ww  . ja  v a 2 s  .com
 * 6 Arguments are expected:
 * 1) boolean if production should be used (true), or sandbox (false)
 * 2) apiKey
 * 3) projectId
 * 4) path to the property file to download (used to look up the fileUri).
 * 5) the locale to download the file for. Can be null if the original file is desired.
 * 6) path to store the file.
 * <pre>
 * @throws IOException if an exception occurs in the course of downloading the specified file.
 * @throws ApiException if an exception occurs while writing translated contents into file
 */
public static void main(String[] args) throws IOException, ApiException {
    File translatedFile = retrieve(args);

    logger.info(String.format(RESULT, translatedFile.getName()));
}

From source file:MainClass.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setAccessory(new LabelAccessory(fileChooser));
    int status = fileChooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("JFileChooser.CANCEL_OPTION");
    }/*from   w w  w  .  java 2 s .co  m*/
}