file - Java - Working with IO - Clarification -


i working on few lessons in java, , instructor started introducing how io working in java. have couple of question experience java programmer clarify.

the piece of code below program creates (notepad) text file in same file directory writing code. after that, prints basic lines of text file.

import java.io.filewriter; //imports filewriter class import java.io.printwriter; //imports printwriter class import java.io.ioexception; //imports ioexception  public class chap17part2 {      public static void main(string[] args) throws ioexception     {         string filename = "grades.txt"; //creating name file         printwriter outfile = new printwriter(new filewriter(filename)); //question 1         outfile.println(85); //prints file         outfile.println(77); //prints file         outfile.close(); //ends buffer, , flushes data file.      }  } 

question 1: due brief explanations instructor, line of code bit confusing me. know in line, creating "outfile" object. after that, calling printwriter constructor, , inside parameters, calling constructor filewriter. inside of constructor, calling name of file created string. confusing part. i'm not understanding printwriter, , filewriter doing. looks filewriter creating our file, , printwriter giving println() method print 2 numbers file. after doing research, have found can pretty achieve same purpose both filewriter, , printwriter. purpose teaching file processing in manner, , 2 classes doing? thank in clarifying me!

the code equivalent

filewriter fw = new filewriter(filename);  printwriter outfile = new printwriter(fw); 

so first creates filewriter, writes characters file, , creates printwriter prints values filewriter.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -