Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:41:55+00:00 2026-06-16T20:41:55+00:00

I want to save a text in a text file and I need to

  • 0

I want to save a text in a text file and I need to save the \n character to delimit the elements in the text. The text is as follow:

“This is a java prog. and It saves text in a .txt file.

You can choose where it should be saved.”

How I can save \n (newline) in a .txt file?

The follow is the code segment I used to save text in text file:

FileOutputStream fout = null;

try {

    fout = new FileOutputStream(destinationFile);

} catch (FileNotFoundException e) {

    System.out.println("output File not found");
    return false;
}

Scanner sc = new Scanner(text);
while (sc.hasNext()) {
    fout.write((sc.next().getBytes()));
}

fout.close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:41:56+00:00Added an answer on June 16, 2026 at 8:41 pm

    this should do the trick:

    while (sc.hasNext()) {
      fout.write((sc.next().getBytes()));
      fout.write("\n".getBytes());
    }
    

    this will write the line you entered into the standard input, then write a newline, so that the file will be separated by newlines

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save a matrix to a text file, so I can read
I need to pull data from a text file, sort it, then save over
I want to save large amounts of text then display them (first in table
I want to use Ckeditor for Entering text and I want to save that
I want to save values as an ArrayList of double in a file. Whenever
I want to save my program's DataModel objects to a file, and be able
I want to get some Strings out of a text file. I know how
I want to be able to save a bitmap image with text from a
A text file is formatted like this: Section 4 Area B Unit 20 stuff
I have some reference data in a text file (~5MB) that I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.