RUVIDEO
Поделитесь видео 🙏

Java Programming Tutorial 81 Reading from Files

📁 Обучение 👁️ 21 📅 05.12.2023

More intensive courses : http://grow-book.blogspot.com/
Abstract video content

what is going on guys welcome to your 81st dropped oral and we're finally

going to learn how to read stuff from a file so as you can already see i created

this Chinese that text file and i added three more records to it so the first

one is Bucky the second one is the ID number and then a name ID number name ID

number name so it has four records in a record is pretty much um OH a row data

so now let's go ahead and figure out all right we're learning how to open the

file we learn how to write this stuff on this file but we don't know how to

access it from a java program so that's what I'm going to be teaching you today

in the thing I didn't tell you is before we use scanner that scanner object to

read from our keyboard using system in but we can actually use scanner to read

from a file as well so let's go ahead and first make a private scanner

variable so i'm gonna name mine scanner x move the cursor out of the way and now

let's go ahead and just make a method to open the file first so public void open

file and let's go ahead and put tried to open the file so we're going to set X

and again here's where we're going to put new scanner and instead of putting

the system in here which would be the keyboard just put new file and put that

Chinese . text speller right yep and now instead of reading from her keyboard

it's actually going to read from this Chinese dot txt file right here so

that's a neat little trick that you can do and if we get any errors just go

ahead and catch those errors exceptions

II and what we want to do let's go ahead and write system out print line and

let's go ahead and print something like

good not find file looks good enough

so now we have a method to open the file easy enough

so what method do we need after this well the story is all about reading

files so let's go ahead and make a method to read the data from that file

so public void

just name it like read a file or something like that and what we want to

do movement off the first thing we want to do is create a while loop and it goes

something like this

while put your file name which is X and then one plant has next and what this is

going to do its built-in method it it's going to make a while loop and it's

going to keep going until it reaches the end of the file so it's going to loop

through this and has next pretty much means if you hover over it

another input so as long as there's something there it's going to continue

as soon as there's nothing there and enriches the end of file this is going

to be false in this while loop is going to break out so that's why we can work

right while x has next it pretty much means while the file X has something in

it so what we want to do is you see each of these records has an ID number a

first-name and lastname so we're going to want three variables to hold those

string a and let's go ahead and copy that

actually we're going to put string 8 equals x dot next and what this means is

pretty much it's going to do this well let me finish right on my variables

don't tell you guys what does string a equals next and this is going to be B

and see what it's going to do is this it's going to loop through the very

first thing it sees and it's going to assign 20 equal to a then it's going to

sign lucky equal to be in Roberts equal to C and then we're going to put after

this is we're just going to go ahead and print those out so system

out Prince actually printf will be better so let's go ahead and print just

three string variables so percent s-space purse and space process in those

variables of course are a B and C so now it's good new is after it gets those

three

it's going to print it out and might want to put a new line there and then

it's going to go all right next sixty a Joe is be in dough is see now i'm going

to print all those out and it's going to keep printing those out until it gets to

the end of the file which is right here and then it's going to break out that

while loop so that's actually the only thing we need in this read file method

right there

so now we just need that one last method and what this is going to do is close

the file so public void closed file just like that and all we want this do is

close that file X and now looks like we got everything check for errors and now

we can go ahead and start putting it in our main so let's go ahead and put great

file i didn't probably up r equals new read file don't take any parameters and

now let's go ahead and put our open filed our . read file and are not closed

file right there

so now with this is good news call open file to open it

read the stuff from it and close it when we're done w

...

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Java Programming Tutorial 81 Reading from Files», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.