1

00:00:01,200  -->  00:00:07,260
Vienneau understand how to read text from a file as well as from the network.

2

00:00:07,320  -->  00:00:09,780
Next thing to learn is how the can read text.

3

00:00:09,920  -->  00:00:10,630
Did they use it.

4

00:00:10,650  -->  00:00:16,510
And does it take cancel reading from console is not that common compared to reading.

5

00:00:16,590  -->  00:00:22,050
Phylogenic book but still there may be instances where we would need that.

6

00:00:22,050  -->  00:00:27,250
For example let's say first typing a server using a program.

7

00:00:27,390  -->  00:00:32,640
Did the java program may take some input from the system admin or the developer.

8

00:00:33,060  -->  00:00:39,180
And based on the input it may do some preliminary checks on only if all of the checks would succeed

9

00:00:39,570  -->  00:00:43,020
then the observer would be started by the program.

10

00:00:43,020  -->  00:00:44,430
So that's just one example.

11

00:00:44,500  -->  00:00:50,760
And there can be many instances where this might be very useful reading from the Ansal self learned

12

00:00:50,790  -->  00:00:54,820
about how we can read text that user enters in a console.

13

00:00:55,620  -->  00:01:01,800
So here we have this new method called Read from standard book as we want to read data from the console

14

00:01:02,100  -->  00:01:07,930
standard input is basically the console and it is in the eye or Demo class that is in the package.

15

00:01:07,950  -->  00:01:08,390
OK.

16

00:01:08,730  -->  00:01:16,030
So here initially we are asking the user to enter first start the next stock in order to continue.

17

00:01:16,220  -->  00:01:21,690
And we are saying we are using buffered reader and that's because later we will also use a different

18

00:01:21,690  -->  00:01:24,860
approach to take the input from the console.

19

00:01:25,290  -->  00:01:27,570
But first let's look at this particular approach.

20

00:01:27,990  -->  00:01:30,880
And we already discussed it in one of the previous lessons.

21

00:01:30,930  -->  00:01:34,320
So we are just going to implement the same code here.

22

00:01:34,350  -->  00:01:40,560
In fact the code is already here and what we're going to do is the user is going to enter the next stock

23

00:01:40,580  -->  00:01:40,900
.

24

00:01:41,160  -->  00:01:47,430
But if the user does not enter the tech stock on you if he enters something else then we would prompt

25

00:01:47,430  -->  00:01:53,000
the user to re-enter the text and we were budak under the user enters the next dock.

26

00:01:53,040  -->  00:01:58,740
So we use the why loop here for that Ironmen when the user and does the text dock then we would exit

27

00:01:58,740  -->  00:01:59,480
the while loop.

28

00:01:59,560  -->  00:01:59,920
OK.

29

00:02:00,150  -->  00:02:04,740
So here we have the play with resources in packs and we have the normal read button which is a buffer

30

00:02:04,740  -->  00:02:07,420
reader which is used for performance.

31

00:02:07,530  -->  00:02:13,210
It is chained to the input stream reader that is don't change to an input stream instance.

32

00:02:13,230  -->  00:02:15,780
So in this case the input stream instances system.

33

00:02:15,810  -->  00:02:22,680
And so on is a variable static variable within the system class and that represents an input stream

34

00:02:22,680  -->  00:02:23,260
instance.

35

00:02:23,280  -->  00:02:25,120
In this case it represents a console.

36

00:02:25,380  -->  00:02:28,700
OK under Carter and coding is UTF 8.

37

00:02:28,770  -->  00:02:34,230
So since this is an input stream instance we can pass system not in our we can pass a file input stream

38

00:02:34,740  -->  00:02:38,180
or even an input stream that represents a remote host.

39

00:02:38,240  -->  00:02:42,990
OK we have seen that in the last lesson and once again we are going to use the read line method from

40

00:02:42,990  -->  00:02:49,710
the buffer reader which gives us a line of text as a string and it is assigned to this variable cardiod

41

00:02:49,830  -->  00:02:50,950
which is a string.

42

00:02:51,270  -->  00:02:57,840
And if it is not equal to none and if it is if it not equal stock then it means that we need to prompt

43

00:02:57,840  -->  00:03:01,130
the user to re-enter the text and that's what it is doing.

44

00:03:01,350  -->  00:03:08,660
But if the user does start then we would exit the while loop and we would print the next contract.

45

00:03:08,790  -->  00:03:09,790
So let's just go ahead.

46

00:03:09,820  -->  00:03:12,770
I'm not on this program.

47

00:03:14,500  -->  00:03:16,810
OK so it is asking us to enter text.

48

00:03:16,830  -->  00:03:19,530
So let's just put some random here.

49

00:03:20,010  -->  00:03:20,260
OK.

50

00:03:20,280  -->  00:03:27,840
So it's once again asking us to enter the next let's decide which you start and there you go.

51

00:03:27,840  -->  00:03:31,330
So we are in the next day.

52

00:03:31,470  -->  00:03:33,090
So that's how you will do it.

53

00:03:33,090  -->  00:03:39,200
So everything is the same except that we are passing system dot and it's a different source.

54

00:03:39,450  -->  00:03:46,780
Now there is also another approach to handle this so you can obviously you can definitely use this matter

55

00:03:47,500  -->  00:03:55,680
but there is also another class which helps us to do it on it's call as the scanner class from Jellico

56

00:03:55,680  -->  00:04:03,410
Trudel package and it was introduced in giallo file and it can be used for this for doing this.

57

00:04:04,260  -->  00:04:07,480
So the input to the scanner constructor is System.

58

00:04:07,510  -->  00:04:07,930
In.

59

00:04:08,080  -->  00:04:08,370
OK.

60

00:04:08,370  -->  00:04:14,400
So this is how you would instantiate a scanner and everything else is say we are asking the user to

61

00:04:14,460  -->  00:04:23,940
enter the text dock and instead of red line we have this medicore next line which would read under data

62

00:04:24,470  -->  00:04:27,380
the data that is read from the console.

63

00:04:27,570  -->  00:04:32,250
So this next line method actually blocks under the user enters a text.

64

00:04:32,630  -->  00:04:35,610
And if it equals start then we are going to exit the loop.

65

00:04:35,730  -->  00:04:38,950
So let's just go ahead and run this.

66

00:04:39,000  -->  00:04:47,350
So once again I put some random because store under Reagan and let's just enter start.

67

00:04:47,920  -->  00:04:49,420
There you go.

68

00:04:49,440  -->  00:04:51,690
So it's exactly identical to that.

69

00:04:52,140  -->  00:04:55,140
And the cool thing about Skynet is that

70

00:04:58,000  -->  00:05:00,120
it's not restricted to just strings.

71

00:05:00,170  -->  00:05:06,230
For example with buffler reader we were reading on E-Strings But here we can also the token that we

72

00:05:06,230  -->  00:05:13,690
enter in the console can also be an end or it can also be along so the text that we understand can be

73

00:05:13,700  -->  00:05:16,570
some primitive also need not be just string.

74

00:05:16,790  -->  00:05:18,410
So we can also do that.

75

00:05:18,400  -->  00:05:26,640
So it kind of provides nice convenient methods to extract the text entered as an OK so we can do that

76

00:05:26,640  -->  00:05:26,720
.

77

00:05:26,720  -->  00:05:32,890
It can also be done using a buffer reader but in that case we would have to parse the string into and

78

00:05:32,900  -->  00:05:34,310
put in or do our set.

79

00:05:34,580  -->  00:05:38,510
So we we would have to use something like an integer Dropbox and method.

80

00:05:38,930  -->  00:05:44,530
But here it is much more cleaner and the scanner itself provides a method to extract the string as an

81

00:05:44,570  -->  00:05:49,350
and so let's just go ahead and vote on it again.

82

00:05:49,400  -->  00:05:55,370
So that's understocked underestimate does asking a store and or some stock good.

83

00:05:55,670  -->  00:05:58,230
So let's just say one two three.

84

00:05:58,320  -->  00:06:02,630
And as you can see it's spending this next thanks to you under the code 1.3.

85

00:06:02,870  -->  00:06:06,100
And there are also methods for like next long necks double and so on.

86

00:06:06,130  -->  00:06:07,110
You can use that.

87

00:06:07,520  -->  00:06:13,640
But if you enter at something else like if you're walking next and but if the string happens to be something

88

00:06:13,630  -->  00:06:20,960
else not on and then it will throw an exception card mis input mismatch exception input mismatch exception

89

00:06:20,960  -->  00:06:22,380
which is a runtime exception.

90

00:06:22,490  -->  00:06:22,960
OK.

91

00:06:23,250  -->  00:06:28,610
So let's also try that.

92

00:06:29,870  -->  00:06:36,740
Now let me just enter the H.C. as you can see Strawson and put mismatch exception.

93

00:06:36,740  -->  00:06:38,180
So that's the thing that's there.

94

00:06:38,180  -->  00:06:41,330
What did you have with the scanner.

95

00:06:41,360  -->  00:06:44,220
It also uses internally a buffer just like buffer reader.

96

00:06:44,230  -->  00:06:46,580
But I think the buffer size is smaller.

97

00:06:46,580  -->  00:06:48,270
That's what I read.

98

00:06:48,320  -->  00:06:53,390
So that's about scanner and this is a little bit of description from the API itself.

99

00:06:53,720  -->  00:06:56,320
So it's not simply a scanner.

100

00:06:56,420  -->  00:06:57,190
OK.

101

00:06:57,290  -->  00:06:59,920
Parses Remedios and string.

102

00:07:00,100  -->  00:07:00,810
OK.

103

00:07:01,000  -->  00:07:04,300
And there is nothing more to it or simply a scanner.

104

00:07:04,750  -->  00:07:11,480
And the way it works is in this case we passed system not in but we can also pass a string to it or

105

00:07:11,620  -->  00:07:18,740
lauching for example or it can be a file also because the input parameter is to the constructor as this

106

00:07:19,200  -->  00:07:20,580
is an input stream.

107

00:07:20,750  -->  00:07:27,530
So obviously you can pass a file also using the file input stream and it would beg to be taxed on it

108

00:07:27,540  -->  00:07:33,080
would tokenize the text which means that it would break the text into individual pieces individual words

109

00:07:33,640  -->  00:07:35,820
and it uses it as a delimiter.

110

00:07:35,840  -->  00:07:37,960
By default it uses whitespace.

111

00:07:38,240  -->  00:07:39,790
So that's how it works.

112

00:07:39,920  -->  00:07:43,230
But you can also pass a different delimiter Also if you want to.

113

00:07:43,890  -->  00:07:51,140
And and then once you do that you can extract each text using methods like next and our next there is

114

00:07:51,130  -->  00:07:56,180
also a method called next order if you want the entire line itself because the text might have several

115

00:07:56,180  -->  00:07:58,760
lines then you would use next line.

116

00:07:58,750  -->  00:08:01,630
So it is basically used to parse text.

117

00:08:01,760  -->  00:08:02,960
OK.

118

00:08:03,110  -->  00:08:09,340
And here let's also try that.

119

00:08:09,740  -->  00:08:11,120
So we have this text.

120

00:08:11,300  -->  00:08:12,260
Hello how are you.

121

00:08:12,250  -->  00:08:13,380
So that's the string.

122

00:08:13,580  -->  00:08:19,820
So we are invoking a different constructor here and we are just checking if the scanner has another

123

00:08:20,180  -->  00:08:22,510
token and if it does then we are printing that.

124

00:08:22,510  -->  00:08:33,050
So we're going to print tokenize and burn this strings up this individual words into that.

125

00:08:36,400  -->  00:08:39,270
So as you can see it is printing the individual words.

126

00:08:39,290  -->  00:08:40,910
Hello how are you.

127

00:08:40,990  -->  00:08:41,600
OK.

128

00:08:41,620  -->  00:08:43,940
Because it's tokenized using whitespace.

129

00:08:43,940  -->  00:08:45,770
And that's how it works by default.

130

00:08:45,880  -->  00:08:46,330
OK.

131

00:08:46,390  -->  00:08:49,740
So there are also these convenient methods like has Next.

132

00:08:49,800  -->  00:08:57,130
Next and even all the Remedios all the methods that can extract the primitives next and has a matter

133

00:08:57,300  -->  00:08:59,410
convenient math associated Metuchen has.

134

00:08:59,410  -->  00:09:05,680
And it's just going to check if the next book and whether it is an end or not if what it does and if

135

00:09:05,690  -->  00:09:10,580
it says Yes if it returns a boolean value or group then you can extract.

136

00:09:10,610  -->  00:09:11,670
It doesn't.

137

00:09:11,880  -->  00:09:13,380
OK you can invoke this method.

138

00:09:13,630  -->  00:09:15,870
So it has those convenience methods.

139

00:09:16,280  -->  00:09:20,680
So you can actually go ahead and use this on anytime you want to parse a text.

140

00:09:20,920  -->  00:09:28,070
You can think of using a scanner for reading from the console you can use either Gunner or the board

141

00:09:28,070  -->  00:09:29,650
reader.

142

00:09:30,670  -->  00:09:31,480
And that's about it.

143

00:09:31,550  -->  00:09:34,360
You can find the find this good updater.

144

00:09:34,520  -->  00:09:36,840
I would more and the resources section.

145

00:09:36,970  -->  00:09:38,520
And thank you and happy coding.
