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:Main.java

public static void main(String[] args) throws Exception {
    File outFile = new File("stdout.txt");
    PrintStream ps = new PrintStream(new FileOutputStream(outFile));

    System.out.println(outFile.getAbsolutePath());

    System.setOut(ps);//from ww w.  j av  a  2s.  c om

    System.out.println("Hello world!");
    System.out.println("Java I/O  is cool!");
}

From source file:com.apress.prospringintegration.customadapters.inbound.eventdriven.fsmon.DirectoryMonitorClient.java

public static void main(String[] args) throws Throwable {
    File[] files = { new File(new File(SystemUtils.getUserHome(), "Desktop"), "test2"),
            new File(new File(SystemUtils.getUserHome(), "Desktop"), "test1") };

    Executor ex = Executors.newFixedThreadPool(10);

    final LinuxInotifyDirectoryMonitor monitor = new LinuxInotifyDirectoryMonitor();
    monitor.setExecutor(ex);/*from  w  w  w  . j  a  v a  2s.c  om*/
    monitor.afterPropertiesSet();

    final DirectoryMonitor.FileAddedListener fileAddedListener = new DirectoryMonitor.FileAddedListener() {
        @Override
        public void fileAdded(File dir, String fn) {
            System.out
                    .println("A new file in " + dir.getAbsolutePath() + " called " + fn + " has been noticed");
        }
    };

    for (File f : files) {
        monitor.monitor(f, fileAddedListener);
    }
}

From source file:Main.java

public static void main(String[] args) {
    File inputFile = new File("test1.txt");
    if (!inputFile.exists()) {
        System.out.println("The input file " + inputFile.getAbsolutePath() + "  does  not  exist.");
        System.out.println("Aborted the   file reading process.");
        return;/* www  . j  a  v  a2 s . com*/
    }
    try (FileChannel fileChannel = new FileInputStream(inputFile).getChannel()) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (fileChannel.read(buffer) > 0) {
            buffer.flip();
            while (buffer.hasRemaining()) {
                byte b = buffer.get();
                System.out.print((char) b);
            }
            buffer.clear();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveList.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 ww .jav  a2  s .c  om
    //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 T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "List";
    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/PrimitiveListTemplate.java"));

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

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveSet.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  . 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 T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "Set";
    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/PrimitiveSetTemplate.java"));

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

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorWritableList.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];// ww  w. j av  a 2s  .  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 T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "List";
    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/WritableListTemplate.java"));

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

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorWritableSet.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  va2s. 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 T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "Set";
    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/WritableSetTemplate.java"));

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

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.jff.searchapicluster.server.mina.Server.java

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

    org.apache.commons.configuration.Configuration config = new PropertiesConfiguration("settings.txt");

    int serverPort = config.getInt("listenPort");

    NioSocketAcceptor acceptor = new NioSocketAcceptor();

    acceptor.getFilterChain().addLast("com/jff/searchapicluster/core/mina/codec",
            new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));

    acceptor.getFilterChain().addLast("logger", new LoggingFilter());

    acceptor.setHandler(new ServerSessionHandler());
    acceptor.bind(new InetSocketAddress(serverPort));

    System.out.println("Listening on port " + serverPort);
    System.out.println("Please enter filename");

    //  open up standard input
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
        String filepath = br.readLine();

        filepath = "/Users/admin/repos/study_repos/kurs_sp/search_api_cluster/SearchApiClusterServer/task.json";
        File file = new File(filepath);
        Logger.d(LOG_TAG, file.getAbsolutePath());

        if (file.exists() && file.isFile()) {

            Gson gson = new Gson();

            SearchTask taskMessage = gson.fromJson(new FileReader(file), SearchTask.class);

            ServerManager serverManager = ServerManager.getInstance();

            Logger.d(LOG_TAG, taskMessage.toString());
            serverManager.startProcessTask(taskMessage);
        } else {//  w  ww .j  a  v a2  s .  com
            Logger.d(LOG_TAG, filepath + "not found");
        }
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyKryoValue.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  .jav  a  2  s .  c om
    //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
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Class name (no packages) of the Key class Ex. String
    //Class name (no packages) of the value class Ex. Integer
    String K = args[3];
    //Specify if you are using a KryoTemplate to generate your classes
    //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used
    //You can customize the name of the class generated
    String kCls = K;

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

    String CLASS_NAME = kCls + "KryoV" + "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/PrimitiveKeyKryoValueMapTemplate.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("#KCLS#", kCls);
        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorKryoKPrimitiveValue.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  a2  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
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[2];
    //Class name (no packages) of the Key class Ex. String
    //Class name (no packages) of the value class Ex. Integer
    String V = args[3];
    //Specify if you are using a KryoTemplate to generate your classes
    //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used
    //You can customize the name of the class generated
    String vCls = V;

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

    String CLASS_NAME = "KryoK" + 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/KryoKeyPrimitiveValueMapTemplate.java"));
        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);

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