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.
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.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
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 now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images

Recommended textbooks for you

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

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