
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Complete in Java using IntelliJ
Here is the code template

Transcribed Image Text:Modify the given template java file (Utils.java) to allow it to read a file (MyTextFile.txt) that resides on the VPL server. The contents of the file are
Hello. This is a text file. My first line.
Read the file. As you read the file, count the number of characters in the file. Return that integer value back to the VPL test script.

Transcribed Image Text:Utils.java
1- import java.io.*;
import java.nio.file.Files;
2
4- public class utils {
1* The method has no input arguments. It only has an output (int).
* You need to specify the file name before reading the file stream. */
7
public static int myMethod ()
{
10 -
11
int bytecounter = 0;
final string fileName = "myTextFile.txt";
12
13
14
15
// This is a try-catch block.
// often used when something could go wrong ...
16
17
like when reading files.
18
19
// The try part: you want this to succeed. Uncomment the try.
/* try */{
20
21 -
22
23
FileInputstream myFileobject
= new FileInputstream(fileName);
24
25
int myData;
26
// in the while loop control parentheses, put a -1 to the right of the !=
// This is because the loop will end when nothing is left to read in the file. (a -1 signal)
while( (myData = myFileobject.read ()) != /* what goes here? */){
system.out.print((char)myData);
bytecounter++;
}
27
28
29 -
30
// the integer is cast to 8-bit char
31
32
33
// Print out the contents.
system.out.println();
34
35
36
// Close the file.
myFileobject.close();
37
38
39
40
// The catch part: catch the program if it fails. Uncomment the catch.
/* catch */(Exception ex)
{
system.out.println("Exception!");
}
41
42
43
44
45
46
// How many 8-bit bytes are there in the text file?
return bytecounter;
47
48
49
50
51 }
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

Knowledge Booster
Similar questions
- Write a C++ Program using classes, functions (recursive and otherwise), arrays and other C++ commands for a friendly game of BlackJack (no bets), according to the rules in Wikipedia. The program would ask if the user wants to play a game and draw the cards. Depending on the drawn cards, the game would progres according to the rules. When the game ends, the program asks if the user wants to play again. You can use a Joker of any card type as a Wild Card valued up to the highest rated card in the deck needed to complete the card hand, if applicable; if not, the player decides the value of the Joker for their card hard (user s hand or program' hand). The game will keep running as long as the user states so.arrow_forwardQUESTION 18 Java uses a hybrid typing system: One system for primitives but everything else is an object. True Falsearrow_forwardWhat are the dangers of C’s approach to encapsulation.arrow_forward
- Define Constant Arrays as Formal Parameters.arrow_forwardWhy Strings in Java are called as Immutable?arrow_forward** in Java ** Suppose we have a set of car. Each car has a number of colors, number of places, dimension and power. According to the set of cad we can have three sets: sedan, sport and pickup truck.1. Write a java program using the previous description.2. Use the flowing concepts,: heritage, polymorphism, encapsulation (get and set method)arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY