Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet57/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   53   54   55   56   57   58   59   60   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Character Streams
Java  Byte  streams  are  utilized  to  perform  output  and  input  of  8-bit  bytes.  On  the  other
hand, Java Character streams are utilized to perform output and input for 16-bit unicode.
In spite of the fact that there are numerous classes identified with character streams yet the
most commonly used ones include Filereader and Filewriter.
It is worth mentioning here that the implementation of Filereader utilizes Fileinputstream
and  Filewriter  utilizes  Fileoutputstream.  This  may  make  you  wonder  as  to  what  is  the
difference  between  the  former  and  latter.  Filereader  peruses  two  bytes  at  once  and
Filewriter  composes  two  bytes  at  once.  We  can  re-compose  above  sample  which  makes
utilization of these two classes to duplicate an info record (having unicode characters) into
an outputfile.txt.
import java.io.*;
public class Mycopyfile {
public static void main(string args[]) throws IOException {
FileReader inputx = invalid;
FileWriter outputx = invalid;
try {
inputx = new FileReader(“inputfile.txt”);


outputx = new FileWriter(“outputfile.txt”);
int charx;
while ((charx = inputx.read()) != -1) {
outputx.write(charx);
}
}
finally {
if (inputx != invalid) {
inputx.close();
}
if (outputx != invalid) {
outputx.close();
}
}
}
Presently how about we have a record inputfile.txt with the accompanying text:
This is for testing purpose only.
Compile  and  execute  the  file  containing  this  code.  The  execution  of  this  code  should
create an output file outputfile.txt.

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   53   54   55   56   57   58   59   60   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling