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:edu.caltech.ipac.firefly.server.util.DsvToDataGroup.java

public static void main(String[] args) {

    try {//from  w ww. j  a  v a 2s.c o  m
        File inf = new File(args[0]);
        DataGroup dg = parse(inf, CSVFormat.DEFAULT);
        IpacTableWriter.save(System.out, dg);
        write(new File(inf.getAbsolutePath() + ".csv"), dg);
        write(new File(inf.getAbsolutePath() + ".tsv"), dg, CSVFormat.TDF);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:DropTypeOnTable.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("Drag Source");
    final Table table = new Table(shell, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        if (i % 2 == 0)
            item.setText("Drop a file");
        if (i % 2 == 1)
            item.setText("Drop text");
    }//from w w w  .j a  v  a2s .  c  om
    DragSource dragSource = new DragSource(label1, DND.DROP_COPY);
    dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance() });
    dragSource.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
                File file = new File("temp");
                event.data = new String[] { file.getAbsolutePath() };
            }
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = "once upon a time";
            }
        }
    });
    DropTarget dropTarget = new DropTarget(table, DND.DROP_COPY | DND.DROP_DEFAULT);
    dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance() });
    dropTarget.addDropListener(new DropTargetAdapter() {
        FileTransfer fileTransfer = FileTransfer.getInstance();

        TextTransfer textTransfer = TextTransfer.getInstance();

        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        public void dragOperationChanged(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        public void dragOver(DropTargetEvent event) {
            event.detail = DND.DROP_NONE;
            TableItem item = (TableItem) event.item;
            if (item == null)
                return;
            int itemIndex = table.indexOf(item);
            if (itemIndex % 2 == 0) {
                int index = 0;
                while (index < event.dataTypes.length) {
                    if (fileTransfer.isSupportedType(event.dataTypes[index]))
                        break;
                    index++;
                }
                if (index < event.dataTypes.length) {
                    event.currentDataType = event.dataTypes[index];
                    event.detail = DND.DROP_COPY;
                    return;
                }
            } else {
                int index = 0;
                while (index < event.dataTypes.length) {
                    if (textTransfer.isSupportedType(event.dataTypes[index]))
                        break;
                    index++;
                }
                if (index < event.dataTypes.length) {
                    event.currentDataType = event.dataTypes[index];
                    event.detail = DND.DROP_COPY;
                    return;
                }
            }
        }

        public void drop(DropTargetEvent event) {
            TableItem item = (TableItem) event.item;
            if (item == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            if (fileTransfer.isSupportedType(event.currentDataType)) {
                String[] files = (String[]) event.data;
                if (files != null && files.length > 0) {
                    item.setText(files[0]);
                }
            }
            if (textTransfer.isSupportedType(event.currentDataType)) {
                String text = (String) event.data;
                if (text != null) {
                    item.setText(text);
                }
            }
        }

    });
    shell.setSize(300, 150);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet185.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 185");
    shell.setLayout(new FillLayout());
    Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("Drag Source");
    final Table table = new Table(shell, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        if (i % 2 == 0)
            item.setText("Drop a file");
        if (i % 2 == 1)
            item.setText("Drop text");
    }/*from   w  w  w.  jav  a 2  s  .  com*/
    DragSource dragSource = new DragSource(label1, DND.DROP_COPY);
    dragSource.setTransfer(TextTransfer.getInstance(), FileTransfer.getInstance());
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
                File file = new File("temp");
                event.data = new String[] { file.getAbsolutePath() };
            }
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = "once upon a time";
            }
        }
    });
    DropTarget dropTarget = new DropTarget(table, DND.DROP_COPY | DND.DROP_DEFAULT);
    dropTarget.setTransfer(TextTransfer.getInstance(), FileTransfer.getInstance());
    dropTarget.addDropListener(new DropTargetAdapter() {
        FileTransfer fileTransfer = FileTransfer.getInstance();
        TextTransfer textTransfer = TextTransfer.getInstance();

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.detail = DND.DROP_NONE;
            TableItem item = (TableItem) event.item;
            if (item == null)
                return;
            int itemIndex = table.indexOf(item);
            if (itemIndex % 2 == 0) {
                int index = 0;
                while (index < event.dataTypes.length) {
                    if (fileTransfer.isSupportedType(event.dataTypes[index]))
                        break;
                    index++;
                }
                if (index < event.dataTypes.length) {
                    event.currentDataType = event.dataTypes[index];
                    event.detail = DND.DROP_COPY;
                    return;
                }
            } else {
                int index = 0;
                while (index < event.dataTypes.length) {
                    if (textTransfer.isSupportedType(event.dataTypes[index]))
                        break;
                    index++;
                }
                if (index < event.dataTypes.length) {
                    event.currentDataType = event.dataTypes[index];
                    event.detail = DND.DROP_COPY;
                    return;
                }
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            TableItem item = (TableItem) event.item;
            if (item == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            if (fileTransfer.isSupportedType(event.currentDataType)) {
                String[] files = (String[]) event.data;
                if (files != null && files.length > 0) {
                    item.setText(files[0]);
                }
            }
            if (textTransfer.isSupportedType(event.currentDataType)) {
                String text = (String) event.data;
                if (text != null) {
                    item.setText(text);
                }
            }
        }

    });
    shell.setSize(300, 150);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:edu.gslis.ts.ChunkToFile.java

public static void main(String[] args) {
    try {// w  w  w .  j  av a  2 s  .  c o  m
        // Get the commandline options
        Options options = createOptions();
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        String inputPath = cmd.getOptionValue("input");
        String indexPath = cmd.getOptionValue("index");
        String eventsPath = cmd.getOptionValue("events");
        String stopPath = cmd.getOptionValue("stop");
        String outputPath = cmd.getOptionValue("output");

        IndexWrapper index = IndexWrapperFactory.getIndexWrapper(indexPath);
        Stopper stopper = new Stopper(stopPath);
        Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper);

        // Setup the filter
        ChunkToFile f = new ChunkToFile();
        if (inputPath != null) {
            File infile = new File(inputPath);
            if (infile.isDirectory()) {
                Iterator<File> files = FileUtils.iterateFiles(infile, null, true);

                while (files.hasNext()) {
                    File file = files.next();
                    System.err.println(file.getAbsolutePath());
                    f.filter(file, queries, index, stopper, outputPath);
                }
            } else
                System.err.println(infile.getAbsolutePath());
            f.filter(infile, queries, index, stopper, outputPath);
        }

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

From source file:com.nuance.expertassistant.ContentCrawler.java

public static void main(String args[]) {
    if (args.length == 0) {
        ContentExtractor.startDocument("Test3", "/Users/abhishek_rohatgi/" + "Test3" + ".xml");
        ContentExtractor.extract("http://www.audihelp.com/auda-147-tyre_repairs.html");
        ContentExtractor.endDocument();// ww w  . j  a  va 2 s .  c o  m
    } else {
        final ContentCrawlerOptions options = new ContentCrawlerOptions(args);
        final ContentCrawlerInputTypes inputType = ContentCrawlerOptions.getInputType();
        if (ContentCrawlerInputTypes.FILE.equals(inputType)) {
            final File outputFile = new File(getOutput());
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }
            translateFile(getInput(), getOutput());
        } else if (ContentCrawlerInputTypes.FOLDER.equals(inputType)) {
            final File outputFolder = new File(getOutput());
            final Collection<File> inputFiles = FileUtils.listFiles(new File(getInput()),
                    new RegexFileFilter("^(.*\\.(html)?)"), DirectoryFileFilter.DIRECTORY);
            for (final File inputFile : inputFiles) {
                final String outputFileName = inputFile.getAbsolutePath().substring(getInput().length())
                        + ".xml";
                final File outputFile = new File(outputFolder, outputFileName);
                if (!outputFile.getParentFile().exists()) {
                    outputFile.getParentFile().mkdirs();
                }
                translateFile(inputFile.getAbsolutePath(), outputFile.getAbsolutePath());
            }

        } else {
            ContentExtractor.startDocument(getInput(), getOutput());
            ContentExtractor.extract(getInput());
            ContentExtractor.endDocument();
        }
    }
}

From source file:com.taobao.tddl.common.SQLPreParserTest.java

public static void main(String[] args) throws IOException {
    //String fileName = "D:/12_code/tddl/trunk/tddl/tddl-parser/sqlsummary-icsg-db0-db15-group-20100901100337-export.xlsx";
    //String fileName = "D:/12_code/tddl/trunk/tddl/tddl-parser/sqlsummary-tcsg-instance-group-20100901100641-export.xlsx";

    int count = 0;
    long time = 0;

    File home = new File(System.getProperty("user.dir") + "/appsqls");
    for (File f : home.listFiles()) {
        if (f.isDirectory() || !f.getName().endsWith(".xlsx")) {
            continue;
        }//from   ww w.  j  ava  2s  .c  o m
        log.info("---------------------- " + f.getAbsolutePath());
        faillog.info("---------------------- " + f.getAbsolutePath());
        Workbook wb = new XSSFWorkbook(new FileInputStream(f));
        Sheet sheet = wb.getSheetAt(0);
        for (Row row : sheet) {
            Cell cell = row.getCell(2);
            if (cell != null && cell.getCellType() == Cell.CELL_TYPE_STRING) {
                String sql = cell.getStringCellValue();

                long t0 = System.currentTimeMillis();
                String tableName = SQLPreParser.findTableName(sql);
                time += System.currentTimeMillis() - t0;
                count++;

                log.info(tableName + " <-- " + sql);
                if (tableName == null) {
                    sql = sql.trim().toLowerCase();
                    if (isCRUD(sql)) {
                        System.out.println("failed:" + sql);
                        faillog.error("failed:" + sql);
                    }
                }
            }
        }
        wb = null;
    }
    faillog.fatal("------------------------------- finished --------------------------");
    faillog.fatal(count + " sql parsed, total time:" + time + ". average time use per sql:"
            + (double) time / count + "ms/sql");
}

From source file:edu.gslis.ts.DumpThriftData.java

public static void main(String[] args) {
    try {//from w  ww.jav a2s .  c  o  m
        // Get the commandline options
        Options options = createOptions();
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        String in = cmd.getOptionValue("i");
        String sentenceParser = cmd.getOptionValue("p");
        String query = cmd.getOptionValue("q");
        String externalCollection = cmd.getOptionValue("e");

        // Get background statistics
        CollectionStats bgstats = new IndexBackedCollectionStats();
        bgstats.setStatSource(externalCollection);

        // Set query
        GQuery gquery = new GQuery();
        gquery.setText(query);
        gquery.setFeatureVector(new FeatureVector(query, null));

        // Setup the filter
        DumpThriftData f = new DumpThriftData();

        if (in != null) {
            File infile = new File(in);
            if (infile.isDirectory()) {
                for (File file : infile.listFiles()) {
                    if (file.isDirectory()) {
                        for (File filefile : file.listFiles()) {
                            System.err.println(filefile.getAbsolutePath());
                            f.filter(filefile, sentenceParser, gquery, bgstats);
                        }
                    } else {
                        System.err.println(file.getAbsolutePath());
                        f.filter(file, sentenceParser, gquery, bgstats);
                    }
                }
            } else
                System.err.println(infile.getAbsolutePath());
            f.filter(infile, sentenceParser, gquery, bgstats);
        }

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

From source file:net.hedges.fandangled.commandline.GenericCli.java

public static void main(String[] args) {
    options = buildOptions();//w w  w. j av  a 2  s.  com

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        verbose = line.hasOption('v');
        if (line.hasOption('h')) {
            usage();
            System.exit(0);
        }
        String template = line.getOptionValue("templates");
        String input = line.getOptionValue("input");
        String output = line.getOptionValue("output");

        String prefix = line.getOptionValue("prefix", "");
        String extension = line.getOptionValue("extension", ".txt");

        File inputFile = new File(input);
        File outputDir = new File(output);
        File templateDir = new File(template);

        checkFilesAndDirectories(inputFile, outputDir, templateDir);

        GenericCodec codec = new GenericCodec();
        codec.setTemplatePath(templateDir.getAbsolutePath());
        codec.setExtension(extension);
        codec.setPrefix(prefix);

        Interface _interface = InterfaceBuilder.parse(inputFile);

        codec.encode(_interface, outputDir);

    } catch (ParseException e) {
        System.err.print(e.getMessage() + "\n");
        usage();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public static void main(String[] args) {
    if (args.length == 1) {
        try {//  ww  w .  j a va2s .c o m
            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:DIA_Umpire_To_Skyline.DIA_Umpire_To_Skyline.java

/**
 * @param args the command line arguments
 *///from w  ww .ja va 2s  . com
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    System.out.println(
            "=================================================================================================");
    System.out.println("DIA-Umpire_To_Skyline (version: " + UmpireInfo.GetInstance().Version + ")");
    if (args.length < 1) {
        System.out.println(
                "command format error, it should be like: java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path NoThreads");
        System.out.println("command : java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path [Option]\n");
        System.out.println("\nOptions");
        System.out.println("\t-t\tNo. of threads, Ex: -t4 (using four threads, default value)");
        System.out.println(
                "\t-cP\tPath of msconvert.exe for mzXML conversion, Ex: -cP (using four threads, default value)");
        return;
    }
    try {
        ConsoleLogger.SetConsoleLogger(Level.DEBUG);
        ConsoleLogger.SetFileLogger(Level.DEBUG,
                FilenameUtils.getFullPath(args[0]) + "diaumpire_to_skyline.log");
    } catch (Exception e) {
        System.out.println("Logger initialization failed");
    }

    Logger.getRootLogger().info("Path:" + args[0]);
    String msconvertpath = "C:/inetpub/tpp-bin/msconvert";

    String WorkFolder = args[0];
    int NoCPUs = 4;

    for (int i = 1; i < args.length; i++) {
        if (args[i].startsWith("-")) {
            if (args[i].startsWith("-cP")) {
                msconvertpath = args[i].substring(3);
                Logger.getRootLogger().info("MSConvert path: " + msconvertpath);
            }
            if (args[i].startsWith("-t")) {
                NoCPUs = Integer.parseInt(args[i].substring(2));
                Logger.getRootLogger().info("No. of threads: " + NoCPUs);
            }
        }
    }

    HashMap<String, File> AssignFiles = new HashMap<>();

    try {
        File folder = new File(WorkFolder);
        if (!folder.exists()) {
            Logger.getRootLogger().info("Path: " + folder.getAbsolutePath() + " cannot be found.");
        }
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isFile() && fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry);
            }
            if (fileEntry.isDirectory()) {
                for (final File fileEntry2 : fileEntry.listFiles()) {
                    if (fileEntry2.isFile() && fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                        AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2);
                    }
                }
            }
        }

        Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size());
        for (File fileEntry : AssignFiles.values()) {
            Logger.getRootLogger().info(fileEntry.getAbsolutePath());
        }

        ExecutorService executorPool = null;
        executorPool = Executors.newFixedThreadPool(3);

        for (File fileEntry : AssignFiles.values()) {
            String mzXMLFile = fileEntry.getAbsolutePath();
            FileThread thread = new FileThread(mzXMLFile, NoCPUs, msconvertpath);
            executorPool.execute(thread);
        }
        executorPool.shutdown();
        try {
            executorPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            Logger.getRootLogger().info("interrupted..");
        }
    } catch (Exception e) {
        Logger.getRootLogger().error(e.getMessage());
        throw e;
    }
    Logger.getRootLogger().info("Job done");
    Logger.getRootLogger().info(
            "=================================================================================================");

}