Example usage for java.io FileReader FileReader

List of usage examples for java.io FileReader FileReader

Introduction

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

Prototype

public FileReader(FileDescriptor fd) 

Source Link

Document

Creates a new FileReader , given the FileDescriptor to read, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

From source file:formats.db.fileformats.csv.RunnerCsv.java

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

    CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(',');

    //initialize the CSVParser object

    CSVParser parser = new CSVParser(new FileReader("D:\\customers.csv"), format);

    List<Customers> customersList = new ArrayList<Customers>();
    for (CSVRecord record : parser) {
        Customers customers = new Customers();

        customers.setId_cs(Integer.parseInt(record.get("id_cs")));
        customers.setF_name(record.get("f_name"));
        customers.setL_name(record.get("l_name"));
        customers.setDiscount(Integer.parseInt(record.get("discount")));
        customers.setLicense(record.get("license"));

        customersList.add(customers);//from w ww .ja  v a 2  s.c om
    }
    //close the parser
    parser.close();

    System.out.println(customersList);
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);//ww  w  .  jav a 2s  .c o  m
    }
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector keyVector = new Vector();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    StyleSheet st = new StyleSheet();
    st.loadTagStyle("body", "leading", "16,0");
    PdfWriter.getInstance(document, new FileOutputStream("html2.pdf"));
    document.open();/*from   w w  w.  j  a  va2  s. co m*/
    ArrayList p = HTMLWorker.parseToList(new FileReader("example.html"), st);
    for (int k = 0; k < p.size(); ++k)
        document.add((Element) p.get(k));
    document.close();
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);/*from  w ww  .j  a v  a2  s .com*/
    }
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector<Object> keyVector = new Vector<Object>();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();/* w  w w. ja va 2  s  .com*/
    PdfContentByte cb = writer.getDirectContent();
    BufferedReader reader = new BufferedReader(new FileReader("a.txt"));
    String line;
    Paragraph p;
    float pos;
    while ((line = reader.readLine()) != null) {
        p = new Paragraph("    " + line);
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(p);
        pos = writer.getVerticalPosition(false);
        cb.moveTo(0, pos);
        cb.lineTo(PageSize.A4.width(), pos);
        cb.stroke();
        if (pos < 90)
            document.newPage();
    }
    reader.close();
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    StyleSheet styles = new StyleSheet();
    styles.loadTagStyle("ol", "leading", "16,0");
    PdfWriter.getInstance(document, new FileOutputStream("html3.pdf"));
    document.open();//from   w ww  . ja v  a  2  s  .  com
    ArrayList objects;
    objects = HTMLWorker.parseToList(new FileReader("data.html"), styles);
    for (int k = 0; k < objects.size(); ++k)
        document.add((Element) objects.get(k));
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (Id int, b CLOB);");

    PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)");

    File file = new File("c:/Java_Dev/data.txt");

    FileReader reader = new FileReader(file);
    pstmt.setCharacterStream(1, reader);

    pstmt.execute();/*from   w  ww  .j  a  va  2  s .c o  m*/

    ResultSet resultSet = pstmt.executeQuery("select b from survey ");

    File data = new File("C:\\a.txt");
    Reader dataReader = resultSet.getCharacterStream(1);
    FileWriter writer = new FileWriter(data);
    char[] buffer = new char[1];
    while (dataReader.read(buffer) > 0) {
        writer.write(buffer);
    }
    writer.close();

    reader.close();
    st.close();
    conn.close();
}

From source file:RegExpExample.java

public static void main(String args[]) {
    String fileName = "RETestSource.java";

    String unadornedClassRE = "^\\s*class (\\w+)";
    String doubleIdentifierRE = "\\b(\\w+)\\s+\\1\\b";

    Pattern classPattern = Pattern.compile(unadornedClassRE);
    Pattern doublePattern = Pattern.compile(doubleIdentifierRE);
    Matcher classMatcher, doubleMatcher;

    int lineNumber = 0;

    try {/*w  w  w .j a  va2 s  . c om*/
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String line;

        while ((line = br.readLine()) != null) {
            lineNumber++;

            classMatcher = classPattern.matcher(line);
            doubleMatcher = doublePattern.matcher(line);

            if (classMatcher.find()) {
                System.out.println("The class [" + classMatcher.group(1) + "] is not public");
            }

            while (doubleMatcher.find()) {
                System.out.println("The word \"" + doubleMatcher.group(1) + "\" occurs twice at position "
                        + doubleMatcher.start() + " on line " + lineNumber);
            }
        }
    } catch (IOException ioe) {
        System.out.println("IOException: " + ioe);
        ioe.printStackTrace();
    }
}

From source file:jsonpractice.jsonpractice1.java

public static void main(String[] args) throws IOException, ParseException {
    JSONParser parser = new JSONParser();
    try {/*from   ww  w  . j  av a2  s .  c o m*/
        Object obj = parser.parse(new FileReader("C:\\Users\\user\\Documents\\CountryJSONFile.json"));
        JSONObject jsonobject = (JSONObject) obj;

        String nameOfCountry = (String) jsonobject.get("Name");
        System.out.println("Name of the Country: " + nameOfCountry);

        long population = (long) jsonobject.get("Population");
        System.out.println("Population of the country is : " + population);

        System.out.println("States are: ");
        JSONArray listOfStates = (JSONArray) jsonobject.get("states");

        Iterator<String> iterator = listOfStates.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } catch (ParseException e) {
    }

}

From source file:com.mycompany.airportdatabasebuilder.DatabaseBuilder.java

public static void main(String[] args) {
    try {//from   w ww .j  a  v  a  2 s  . c  om
        Dao dao = new Dao();
        JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
        CSVReader reader = new CSVReader(new FileReader("airportdata2.csv"));
        String[] nextLine;
        int i = 0;
        while ((nextLine = reader.readNext()) != null) {
            if (nextLine[4] == null || nextLine[4].equals(""))
                System.out.println("empty code found");
            else {
                jdbcTemplate.update(
                        "INSERT INTO airportdata (airport_name, city, country, iata) VALUES(?, ?, ?, ?)",
                        nextLine[1], nextLine[2], nextLine[3], nextLine[4]);
            }
            i++;
        }

        // Airport(1)/ City(2)/ Country(3)/ Code(4)
        System.out.println(i + " rows were read");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DatabaseBuilder.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(DatabaseBuilder.class.getName()).log(Level.SEVERE, null, ex);
    }
}