Example usage for java.io FileNotFoundException toString

List of usage examples for java.io FileNotFoundException toString

Introduction

In this page you can find the example usage for java.io FileNotFoundException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.idega.util.Stripper.java

public static void main(String[] args) {
    // Stripper stripper1 = new Stripper();

    if (args.length != 2) {
        System.err.println("Auli.  tt a hafa tvo parametra me essu, innskr og tskr");

        return;//www. j ava2 s  . c om
    }

    BufferedReader in = null;
    BufferedWriter out = null;

    try {
        in = new BufferedReader(new FileReader(args[0]));
    } catch (java.io.FileNotFoundException e) {
        System.err.println("Auli. Error : " + e.toString());

        return;
    }

    try {
        out = new BufferedWriter(new FileWriter(args[1]));
    } catch (java.io.IOException e) {
        System.err.println("Auli. Error : " + e.toString());
        IOUtils.closeQuietly(in);
        return;
    }

    try {
        String input = in.readLine();
        int count = 0;
        while (input != null) {
            int index = input.indexOf("\\CVS\\");
            if (index > -1) {
                System.out.println("Skipping : " + input);
                count++;
            } else {
                out.write(input);
                out.newLine();
            }

            input = in.readLine();
        }
        System.out.println("Skipped : " + count);
    } catch (java.io.IOException e) {
        System.err.println("Error reading or writing file : " + e.toString());
    }

    try {
        in.close();
        out.close();
    } catch (java.io.IOException e) {
        System.err.println("Error closing files : " + e.toString());
    }
}

From source file:displayStructureAsPDFTable.java

public static void main(String args[]) {
    draw2d mk = new draw2d();
    String[] filesToDraw = mk.parseCommandLineOptions(args);

    displayStructure ds = null;//from  w  w w.ja v  a 2s.c  o m
    IteratingMDLReader imdlr;

    if (tabular)
        oformat = "PDF";

    if (verbose)
        System.out.println("Output format is " + oformat);
    if (tabular) {
        if (verbose)
            System.out.println("Making a tabular PDF with " + ncol + " columns");
        ds = new displayStructureAsPDFTable(withH, width, height, scale, ncol, props, doColor, outputDirectory);
    }
    try {
        imdlr = new IteratingMDLReader(new BufferedReader(new FileReader(filesToDraw[0])),
                DefaultChemObjectBuilder.getInstance());
        int cnt = 1;
        while (imdlr.hasNext()) {
            if (verbose) {
                System.out.println("Processing molecule " + cnt);
            }
            IMolecule m = (IMolecule) imdlr.next();

            // do atom typing
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m);
            if (!tabular) {
                ds = new displayStructure(withH, width, height, scale, doColor, oformat, outputDirectory);
            }
            assert ds != null;
            ds.drawStructure(m, cnt);
            cnt = cnt + 1;
        }
        if (ds != null)
            ds.close();
        System.exit(0);
    } catch (FileNotFoundException fnf) {
        System.out.println(fnf.toString());
    } catch (Exception fnf) {
        System.out.println(fnf.toString());
        fnf.printStackTrace();
    }
}

From source file:org.dspace.content.crosswalk.XSLTDisseminationCrosswalk.java

/**
 * Simple command-line rig for testing the DIM output of a stylesheet.
 * Usage:  java XSLTDisseminationCrosswalk  <crosswalk-name> <handle> [output-file]
 */// w  ww.  j a v a  2 s  .  co m
public static void main(String[] argv) throws Exception {
    log.error("started.");
    if (argv.length < 2 || argv.length > 3) {
        System.err.println("Usage:  java XSLTDisseminationCrosswalk <crosswalk-name> <handle> [output-file]");
        log.error("You started Dissemination Crosswalk Test/Export with a wrong number of parameters.");
        System.exit(1);
    }

    String xwalkname = argv[0];
    String handle = argv[1];
    OutputStream out = System.out;
    if (argv.length > 2) {
        try {
            out = new FileOutputStream(argv[2]);
        } catch (FileNotFoundException e) {
            System.err.println("Can't write to the specified file: " + e.getMessage());
            System.err.println("Will write output to stdout.");
        }
    }

    DisseminationCrosswalk xwalk = (DisseminationCrosswalk) PluginManager
            .getNamedPlugin(DisseminationCrosswalk.class, xwalkname);
    if (xwalk == null) {
        System.err.println("Error: Cannot find a DisseminationCrosswalk plugin for: \"" + xwalkname + "\"");
        log.error("Cannot find the Dissemination Crosswalk plugin.");
        System.exit(1);
    }

    context = new Context();
    context.turnOffAuthorisationSystem();

    DSpaceObject dso = null;
    try {
        dso = HandleManager.resolveToObject(context, handle);
    } catch (SQLException e) {
        System.err.println(
                "Error: A problem with the database connection occurred, check logs for further information.");
        System.exit(1);
    }

    if (null == dso) {
        System.err.println("Can't find a DSpaceObject with the handle \"" + handle + "\"");
        System.exit(1);
    }

    if (!xwalk.canDisseminate(dso)) {
        System.err.println("Dissemination Crosswalk can't disseminate this DSpaceObject.");
        log.error("Dissemination Crosswalk can't disseminate this DSpaceObject.");
        System.exit(1);
    }

    Element root = null;
    try {
        root = xwalk.disseminateElement(dso);
    } catch (Exception e) {
        // as this script is for testing dissemination crosswalks, we want
        // verbose information in case of an exception.
        System.err.println("An error occurred while processing the dissemination crosswalk.");
        System.err.println("=== Error Message ===");
        System.err.println(e.getMessage());
        System.err.println("===  Stack Trace  ===");
        e.printStackTrace();
        System.err.println("=====================");
        log.error("Caught: " + e.toString() + ".");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
        System.exit(1);
    }

    try {
        XMLOutputter xmlout = new XMLOutputter(Format.getPrettyFormat());
        xmlout.output(new Document(root), out);
    } catch (Exception e) {
        // as this script is for testing dissemination crosswalks, we want
        // verbose information in case of an exception.
        System.err.println("An error occurred after processing the dissemination crosswalk.");
        System.err.println("The error occurred while trying to print the generated XML.");
        System.err.println("=== Error Message ===");
        System.err.println(e.getMessage());
        System.err.println("===  Stack Trace  ===");
        System.err.println(e.getStackTrace());
        System.err.println("=====================");
        log.error("Caught: " + e.toString() + ".");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
        System.exit(1);
    }

    context.complete();
    if (out instanceof FileOutputStream) {
        out.close();
    }
}

From source file:Main.java

public static List<String> createListFromFile(File f) {
    List<String> retList = new ArrayList<String>();
    FileInputStream fis;/*from  ww w  .j  a v  a  2s.c o m*/
    BufferedReader br;
    try {
        fis = new FileInputStream(f);
        InputStreamReader isr = new InputStreamReader(fis);
        br = new BufferedReader(isr);

        String nStr;
        nStr = br.readLine();
        while (nStr != null) {
            retList.add(nStr);
            nStr = br.readLine();
        }

        br.close();
        fis.close();
    } catch (FileNotFoundException e) {
        logger.severe(e.toString());
        e.printStackTrace();
    } catch (IOException e) {
        logger.severe(e.toString());
        e.printStackTrace();
    }

    return retList;
}

From source file:org.musicpd.activities.fragments.LicenseFragment.java

private static String loadLicenseText(Context context) {
    String out = null;// ww w  .  ja  v a  2  s  .  c  o m

    try {
        InputStream is = context.getAssets().open(LCNSE_FILE);

        if (is != null) {
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);

            StringBuilder license = new StringBuilder();

            while (true) {
                String readLine = br.readLine();
                if (readLine == null)
                    break;
                license.append(readLine).append("\n");
            }

            br.close();

            out = license.toString();
        }
    } catch (FileNotFoundException e) {
        System.out.println("File not found: " + e.toString());
    } catch (Exception e) {
        System.out.println("Can not read file: " + e.toString());
    }

    return out;
}

From source file:org.artifactory.ui.utils.UnitUtils.java

/**
 * get artifact info from pom//  w  w w .  ja  v a2s. c om
 *
 * @param file - current file
 * @return artifact info
 */
private static MavenArtifactInfo getArtifactInfoFromPom(File file, boolean isPom) {
    MavenArtifactInfo mavenArtifactInfo = null;
    try {
        InputStream pomInputStream = new FileInputStream(file);
        mavenArtifactInfo = MavenModelUtils.mavenModelToArtifactInfo(pomInputStream);
        if (isPom) {
            mavenArtifactInfo.setType("pom");
        }
    } catch (FileNotFoundException e) {
        log.error(e.toString());
    } catch (XmlPullParserException e) {
        log.error(e.toString());
    } catch (IOException e) {
        log.error(e.toString());
    }
    return mavenArtifactInfo;
}

From source file:org.openmrs.mobile.utilities.FormsLoaderUtil.java

private static String copyFormFromAssets(String fileName, InputStream in) {
    File form = new File(OpenMRS.FORMS_PATH, fileName);
    try {// w w  w  .  j a v  a  2s . c o  m
        form.createNewFile();
        FileOutputStream out = new FileOutputStream(form);
        IOUtils.copy(in, out);
    } catch (FileNotFoundException fnfx) {
        OpenMRS.getInstance().getOpenMRSLogger().d(fnfx.toString());
    } catch (IOException e) {
        OpenMRS.getInstance().getOpenMRSLogger().d(e.toString());
    }
    return saveOrUpdateForm(form);
}

From source file:org.openmrs.client.utilities.FormsLoaderUtil.java

private static Uri copyFormFromAssets(String fileName, InputStream in) {
    File form = new File(OpenMRS.FORMS_PATH, fileName);
    try {/*  w ww .j a  v a 2 s  . c o  m*/
        form.createNewFile();
        FileOutputStream out = new FileOutputStream(form);
        IOUtils.copy(in, out);
    } catch (FileNotFoundException fnfx) {
        OpenMRS.getInstance().getOpenMRSLogger().d(fnfx.toString());
    } catch (IOException e) {
        OpenMRS.getInstance().getOpenMRSLogger().d(e.toString());
    }
    return saveDefaultFormToDB(form, form.getAbsolutePath());
}

From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java

public static boolean saveReport(String reportContent, String reportFilePath) {
    PrintWriter out;//from www.  ja  v a 2 s  .  com
    try {
        out = new PrintWriter(reportFilePath);
        out.println(reportContent);
        out.flush();
        out.close();
        log.debug("Saved " + reportFilePath);
        return true;
    } catch (FileNotFoundException e) {
        log.error(e.toString());
        return false;
    }
}

From source file:Zip.java

/**
 * Create a OutputStream on a given file, transparently compressing the data
 * to a Zip file whose name is the provided file path, with a ".zip"
 * extension added.// w w  w. j  a v  a 2 s  .  c  o m
 *
 * @param file the file (with no zip extension)
 *
 * @return a OutputStream on the zip entry
 */
public static OutputStream createOutputStream(File file) {
    try {
        String path = file.getCanonicalPath();
        FileOutputStream fos = new FileOutputStream(path + ".zip");
        ZipOutputStream zos = new ZipOutputStream(fos);
        ZipEntry ze = new ZipEntry(file.getName());
        zos.putNextEntry(ze);

        return zos;
    } catch (FileNotFoundException ex) {
        System.err.println(ex.toString());
        System.err.println(file + " not found");
    } catch (Exception ex) {
        System.err.println(ex.toString());
    }

    return null;
}