— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet419/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   415   416   417   418   419   420   421   422   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Just Flush It. Calls to writer.fl ush() say, “send whatever’s in the buffer, now!”
buffers give you a temporary holding 
place to group things until the holder 
(like the cart) is full. You get 
to make 
far fewer trips when you use a buffer.
BufferedWriter writer = new BufferedWriter(new FileWriter(aFile));
Notice that we don’t even 
need to keep a reference to 
the FileWriter object. The 
only thing we care about is the 
BufferedWriter, because that’s 
the object we’ll call methods 
on, and when we close the 
BufferedWriter, it will take 
care of the rest of the chain.


454
 
chapter 14
Reading from a Text File
Reading text from a fi le is simple, but this time we’ll use a File 
object to represent the fi le, a FileReader to do the actual reading, 
and a BufferedReader to make the reading more effi cient.
The read happens by reading lines in a while loop, ending the loop 
when the result of a readLine() is null. That’s the most common 
style for reading data (pretty much anything that’s not a Serialized 
object): read stuff in a while loop (actually a while loop test), 
terminating when there’s nothing left to read (which we know 
because the result of whatever read method we’re using is null).
What’s 2 + 2?/4
What’s 20+22/42
A file with two lines of text.
import java.io.*;
class ReadAFile {
public static void main (String[] args) {
try {
File myFile = new File(“MyText.txt”);
FileReader fi leReader = new FileReader(myFile);
BufferedReader reader = new BufferedReader(fi leReader);
String line = null;
while ((line = reader.readLine()) != null) {

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   415   416   417   418   419   420   421   422   ...   555




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish