Example usage for java.io FileWriter FileWriter

List of usage examples for java.io FileWriter FileWriter

Introduction

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

Prototype

public FileWriter(FileDescriptor fd) 

Source Link

Document

Constructs a FileWriter given a file descriptor, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

From source file:org.jfree.chart.demo.Display.java

/**
 * Launch the application.//from   w  ww. j  a v a 2s. c o m
 */
public static void main(String[] args) throws IOException {

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Display window = new Display();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ////////////
        }
    });

    try {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        File dataFile = new File("data.txt");
        FileWriter fw = new FileWriter(dataFile);
        BufferedWriter bw = new BufferedWriter(fw);
        DataParser datIn = new DataParser(effectiveX, effectiveY);

        //while(!enabled){}//spin until enabled

        while ((s = in.readLine()) != null && s.length() != 0 && enabled) {
            // System.out.println(s);
            if (datIn.parseString(s)) {
                bw.write(s);
                bw.write('\n');
                bw.flush();
                panel_1.plotCoords(datIn.getX(), datIn.getFlippedY());
                TimeElapsed.setText(Double.toString(datIn.getTime()));
            }
        }

        bw.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:edu.internet2.middleware.psp.names.CreateLdapNames.java

/**
 * @param args/*from   ww  w .j a va  2  s  .  com*/
 */

public static void main(String[] args) {

    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter("/tmp/people.ldif"));

        RandomCollection<String> givenNames = readGivenNames();

        RandomCollection<String> surnames = readSurnames();

        for (int i = 0; i < 1000; i++) {
            String surname = surnames.next();
            String givenName = givenNames.next();
            String ldif = getLdif(i, givenName, surname);
            // System.out.println(ldif);
            writer.write(ldif);
            writer.write("\n");
        }

        writer.close();

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

From source file:CopyLines.java

public static void main(String[] args) throws IOException {
    BufferedReader inputStream = null;
    PrintWriter outputStream = null;

    try {//from   w  w w.  j  a va  2  s.  c o  m
        inputStream = new BufferedReader(new FileReader("xanadu.txt"));
        outputStream = new PrintWriter(new FileWriter("characteroutput.txt"));

        String l;
        while ((l = inputStream.readLine()) != null) {
            outputStream.println(l);
        }
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:BufferedCopy.java

public static void main(String[] args) throws IOException {
    BufferedReader inputStream = null;
    BufferedWriter outputStream = null;

    try {/*from   ww  w  . j a  va2s. c o m*/
        inputStream = new BufferedReader(new FileReader("xanadu.txt"));
        outputStream = new BufferedWriter(new FileWriter("characteroutput.txt"));

        int c;
        while ((c = inputStream.read()) != -1) {
            outputStream.write(c);
        }
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:CounterDemo.java

public static void main(String[] args) throws IOException {
    CountReader cr = new CountReader(new FileReader("xanadu.txt"), 'e');
    CountWriter cw = new CountWriter(new FileWriter("outagain.txt"), 'e');
    int c = 0;/*w  w w  . ja  v  a  2 s .  c  om*/
    while ((c = cr.read()) != -1) {
        cw.write(c);
    }
    System.out.println(cr.getCount());
    System.out.println(cw.getCount());
    cr.close();
    cw.close();
}

From source file:com.opengamma.bbg.loader.BloombergSwaptionFileLoader.java

/**
 * Little util to parse swaption tickers into a csv for further analysis.
 * @param args command line params/*  w  w  w  . j  a v  a 2  s .  co m*/
 */
public static void main(String[] args) { // CSIGNORE
    CSVReader csvReader = null;
    CSVWriter csvWriter = null;
    try {
        csvReader = new CSVReader(new BufferedReader(new FileReader(args[0])));
        csvWriter = new CSVWriter(new BufferedWriter(new FileWriter(args[1])));
        String[] line;
        Pattern pattern = Pattern.compile("^(\\w\\w\\w).*?(\\d+)(M|Y)(\\d+)(M|Y)\\s*?(PY|RC)\\s*?(.*)$");
        BloombergReferenceDataProvider rawBbgRefDataProvider = getBloombergSecurityFileLoader();
        MongoDBValueCachingReferenceDataProvider bbgRefDataProvider = MongoCachedReferenceData
                .makeMongoProvider(rawBbgRefDataProvider, BloombergSwaptionFileLoader.class);
        while ((line = csvReader.readNext()) != null) {
            String name = line[NAME_FIELD];
            Matcher matcher = pattern.matcher(name);
            if (matcher.matches()) {
                String ccy = matcher.group(1);
                String swapTenorSize = matcher.group(2);
                String swapTenorUnit = matcher.group(3);
                String optionTenorSize = matcher.group(4);
                String optionTenorUnit = matcher.group(5);
                String payReceive = matcher.group(6);
                String distanceATM = matcher.group(7);

                String buid = "/buid/" + line[BUID_FIELD];
                String value = bbgRefDataProvider.getReferenceDataValue(buid, "TICKER");
                csvWriter.writeNext(new String[] { name, ccy, swapTenorSize, swapTenorUnit, optionTenorSize,
                        optionTenorUnit, payReceive, distanceATM, value });
            } else {
                s_logger.error("Couldn't parse " + name + " field");
            }

        }
    } catch (IOException ioe) {
        s_logger.error("Error while reading file", ioe);
    } finally {
        IOUtils.closeQuietly(csvReader);
        IOUtils.closeQuietly(csvWriter);
    }
}

From source file:com.waku.mmdataextract.ComprehensiveSearch.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    FileWriter fw = null;//w  ww .j  ava  2  s  .  c om
    try {
        fw = new FileWriter(new File("output/ComprehensiveSearch.csv"));
        fw.write(
                ",??,?,?,,?,??,,?,1,2,3,\n");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Document firstPage = MyHttpClient.getAsDom4jDoc(START_ACTION);
    // System.out.println(doc.asXML());
    List<Element> brandOptions = firstPage.selectNodes("//select[@name='brandId']/option");
    for (Element brandOption : brandOptions) {
        String brandId = brandOption.attributeValue("value");
        if (!brandId.equalsIgnoreCase("0")) {
            for (int i = 1; true; i++) {
                logger.info("Get brandId/page -> " + brandId + "/" + i);
                if (searchDone(fw, brandId, i)) {
                    break;
                }
            }
        }
    }
    try {
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    logger.info("----> Done!");

    logger.info("----> Start to compare production search ... ");
    CompareProductions.start(prodIdList, 0);
}

From source file:no.uib.tools.OnthologyHttpClient.java

public static void main(String[] args) {
    try {//from  w w w.  j a  va 2s .co m
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet getRequest = new HttpGet(
                "http://www.ebi.ac.uk/ols/api/ontologies/mod/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMOD_00861/descendants?size=2002");
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed to get the PSIMOD onthology : HTTP error code : "
                    + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        FileWriter fw = new FileWriter("./mod.json");
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            fw.write(output);
        }

        fw.close();
        httpClient.close();

    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:com.redhat.poc.jdg.bankofchina.util.GenerateUserIdCsv.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*from ww  w.  j  av  a  2  s  .  com*/
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        ReadCsvFile(i);
    }

    System.out.println();
    System.out.println("%%%%%%%%%  " + csvFileStart + "-" + csvFileEnd
            + " ? userid.csv ,? %%%%%%%%%");
    System.out.println("%%%%%%%%% userid.csv  " + userIdList.size() + " ? %%%%%%%%%");
    CSVWriter writer = new CSVWriter(new FileWriter(CSV_FILE_PATH + "userid.csv"));
    writer.writeAll(userIdList);
    writer.flush();
    writer.close();
}

From source file:com.diskoverorta.utils.JsonConvertor.java

public static void main(String[] args) throws IOException {
    JsonConvertor js = new JsonConvertor();
    js.JsonConvertor();//from w  ww . j  a  v  a 2s  .  co m
    BufferedWriter bf = new BufferedWriter(new FileWriter("/home/serendio/jaroutput-json.txt"));
    bf.write(js.JsonConvertor());
    bf.newLine();
    bf.flush();
    bf.close();
}