Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

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

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:gda.util.PackageMaker.java

/**
 * @param args//from   w  w w .  j a v a2 s.co  m
 */
public static void main(String args[]) {
    String destDir = null;
    if (args.length == 0)
        return;
    String filename = args[0];
    if (args.length > 1)
        destDir = args[1];
    try {
        ClassParser cp = new ClassParser(filename);
        JavaClass classfile = cp.parse();
        String packageName = classfile.getPackageName();
        String apackageName = packageName.replace(".", File.separator);
        if (destDir != null)
            destDir = destDir + File.separator + apackageName;
        else
            destDir = apackageName;
        File destFile = new File(destDir);
        File existFile = new File(filename);
        File parentDir = new File(existFile.getAbsolutePath().substring(0,
                existFile.getAbsolutePath().lastIndexOf(File.separator)));
        String allFiles[] = parentDir.list();
        Vector<String> selectedFiles = new Vector<String>();
        String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf("."));
        for (int i = 0; i < allFiles.length; i++) {
            if (allFiles[i].startsWith(toMatch + "$"))
                selectedFiles.add(allFiles[i]);
        }
        FileUtils.copyFileToDirectory(existFile, destFile);
        Object[] filestoCopy = selectedFiles.toArray();
        for (int i = 0; i < filestoCopy.length; i++) {
            FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile);
        }
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame(Main.class.getSimpleName());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JTree tree = new JTree(createTreeModel(new File(System.getProperty("user.dir")), true));
    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        @Override/*w  ww.j a v a  2 s . c  o  m*/
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                if (node.getUserObject() instanceof File) {
                    setText(((File) node.getUserObject()).getName());
                }
            }
            return this;
        }
    });
    tree.getSelectionModel().addTreeSelectionListener(e -> {
        Object object = tree.getLastSelectedPathComponent();
        if (object instanceof DefaultMutableTreeNode) {
            Object userObject = ((DefaultMutableTreeNode) object).getUserObject();
            if (userObject instanceof File) {
                File file = (File) userObject;
                System.out.println(
                        "Selected file" + file.getAbsolutePath() + " Is directory? " + file.isDirectory());
            }
        }
    });
    JScrollPane pane = new JScrollPane(tree);
    frame.add(pane);
    frame.setSize(400, 600);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    // create new file
    File f = new File("c:/text.txt");

    // true if the file is executable
    boolean bool = f.canExecute();

    // find the absolute path
    String a = f.getAbsolutePath();

    // prints absolute path
    System.out.print(a);//from  ww w . j  a va2 s  .c  om

    // prints
    System.out.println(" is executable: " + bool);

}

From source file:Main.java

public static void main(String[] args) {
    File file = null;
    WordExtractor extractor = null;//from  w w  w .  j  a v a  2 s  .c  o m
    try {

        file = new File("c:\\New.doc");
        FileInputStream fis = new FileInputStream(file.getAbsolutePath());
        HWPFDocument document = new HWPFDocument(fis);
        extractor = new WordExtractor(document);
        String[] fileData = extractor.getParagraphText();
        for (int i = 0; i < fileData.length; i++) {
            if (fileData[i] != null)
                System.out.println(fileData[i]);
        }
    } catch (Exception exep) {
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitivePrimitive.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];/*  w  w w  .jav a  2  s  . co m*/
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[3];
    //Class name (no packages) of the Key class Ex. String
    String K = args[4];
    //Class name (no packages) of the value class Ex. Integer
    String V = args[5];

    String kCls = K;
    String vCls = V;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }
    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = kCls + vCls + "Map"; //Default
    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/JavaLangBasedMapTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#VCLS#", vCls);

        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorWritableKeyPrimitiveValue.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//from  ww  w . j  a va  2s .co m
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[3];
    //Class name (no packages) of the Key class Ex. String
    String K = args[4];
    //Class name (no packages) of the value class Ex. Integer
    String V = args[5];
    String kCls = K;
    String vCls = V;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }
    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = kCls + vCls + "Map"; //Default

    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(new File(
                root.getAbsolutePath() + "/src/main/resources/WritableKeyPrimitiveValueMapTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#VCLS#", vCls);

        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorWritableKeyWritableValue.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//from ww  w . j  a va 2 s. c  o m
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[3];
    //Class name (no packages) of the Key class Ex. String
    String K = args[4];
    //Class name (no packages) of the value class Ex. Integer
    String V = args[5];
    String kCls = K;
    String vCls = V;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }
    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = kCls + vCls + "Map"; //Default

    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(new File(
                root.getAbsolutePath() + "/src/main/resources/WritableKeyWritableValueMapTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#VCLS#", vCls);

        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyWritableValue.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//from   w  w w  .  j  a  v  a  2 s.com
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[3];
    //Class name (no packages) of the Key class Ex. String
    String K = args[4];
    //Class name (no packages) of the value class Ex. Integer
    String V = args[5];
    String vWritableCls = args[6];
    String kCls = K;
    String vCls = V;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }
    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = kCls + vCls + "Map"; //Default

    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(new File(
                root.getAbsolutePath() + "/src/main/resources/PrimitiveKeyWritableValueMapTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#VCLS#", vCls);
        program = program.replaceAll("#VWRITABLECLS#", vWritableCls);
        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.ClusterCentroidsMain.java

public static void main(String[] args) throws Exception {
    //        String clutoVectors = args[0];
    //        String clutoOuputClusters = args[1];
    //        String outputClusterCentroids = args[2];

    File[] files = new File("//home/user-ukp/data2/debates-ranked.100-xmi").listFiles(new FilenameFilter() {
        @Override/*  w  w  w .  j av a  2s  .  c o m*/
        public boolean accept(File dir, String name) {
            //                        return name.startsWith("arg") && name.endsWith(".mat");
            return name.startsWith("sent") && name.endsWith(".mat");
        }
    });
    for (File matFile : files) {
        String clutoVectors = matFile.getAbsolutePath();
        //            String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.100";
        String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.1000";
        String outputClusterCentroids = matFile.getAbsolutePath() + ".bin";

        TreeMap<Integer, Vector> centroids = computeClusterCentroids(clutoVectors, clutoOuputClusters);

        // and serialize
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(
                new FileOutputStream(outputClusterCentroids));
        objectOutputStream.writeObject(centroids);
        IOUtils.closeQuietly(objectOutputStream);
    }

    //        System.out.println(centroids);
    //        embeddingsToDistance(args[0], centroids, args[2]);
}

From source file:de.doering.dwca.iocwbn.ChecklistBuilder.java

public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
    ChecklistBuilder builder = new ChecklistBuilder();
    File archive = builder.build();
    System.out.println("Archive generated at " + archive.getAbsolutePath());
}