1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ankoles [38]
3 years ago
13

Given a Scanner reference variable named input that has been associated with an input source consisting of a sequence of lines,

write the code necessary to read in every line and print them all out on a single line, separated by a space.Hint: Use input.nextLine() to read a line and use input.hasNextLine() to test if the input has a next line available to read.
Computers and Technology
1 answer:
Ratling [72]3 years ago
3 0

Answer:

Explanation:

Code

import java.util.Scanner;

public class FileReader{

  public static void main(String []args) throws FileNotFoundException {

      Scanner scanner = new Scanner(new FileInputStream(new File("D:/input.txt")));

      String output="";

      while(scanner.hasNextLine()){

          output+=scanner.nextLine()+" ";

      }

      System.out.println(output);

  }

}

Code Explanation

Create scanner object by passing file input stream which will read file as input.

Then declare a string variable which will cancatinate the file text into single line util we don't have any other input from scanner.

Then print that output.

Input File

Hello this is dummy

file.

happy holidays

bye

Output

Hello this is dummy file. happy holidays bye

You might be interested in
Match the limits of the user with an appropriate design response. 1. severe arthritis, unable to type or use a mouse on a reliab
ololo11 [35]
Idk........................
4 0
3 years ago
Anyone else having problems with edg?
Kamila [148]
No what’s your problem on edge
4 0
3 years ago
Why should you stay out of the open space to the right of a semi tractor trailer?
dimulka [17.4K]
The right side to a semi tractor trailer is their huge blind side, meaning the driver can't see you, and may merge lanes with you, thus crashing into you.
5 0
3 years ago
Read 2 more answers
If you wanted to detect x-rays coming from the sun,where would you place the detector? Why?
Temka [501]
You would place it in orbit around Earth, as most X-rays are absorbed by the atmosphere, so you would want the detector outside of the atmosphere to accurately detect the X-rays.
5 0
3 years ago
Can someone help me plz
xxMikexx [17]

Answer:

ok but on what tho

Explanation:

plz explain yourself

8 0
3 years ago
Read 2 more answers
Other questions:
  • How does the use of modules provide flexibility in a structured programming design?
    14·2 answers
  • 1. How does inertia affect a person who is not wearing a seatbelt during a collision? 
    14·2 answers
  • What sends massive amounts of email to a specific person or system that can cause that user's server to stop functioning? mail b
    6·1 answer
  • _____ refers to displaying information for the user's view.
    14·2 answers
  • An IT technician has manually configured an IP address on a laptop for a new employee. Each time the employee tries to connect t
    10·1 answer
  • Which of the following is a name for the place an information services and support professional might work? software development
    15·2 answers
  • Prompts what is a row?
    7·1 answer
  • What do you understand by storage devices ? Name any two storage devices.​
    11·2 answers
  • What will you see on the next line?<br> &gt;&gt;&gt;int(12.8)<br> ___
    15·1 answer
  • HELP 20 points THIS IS ON EDGE IF YOU DON'T KNOW THE ANSWER DON'T RESPOND
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!