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

  • SEARCH
  • Home
  • 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 9027937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:52:01+00:00 2026-06-16T06:52:01+00:00

I am new in java! I use this code to write data to a

  • 0

I am new in java!
I use this code to write data to a .txt file:

try { 
String content = "This is the content to write into file";
File file = new File("/users/mkyong/filename.txt");

// if file doesnt exists, then create it

if ( !file.exists() ) {
    file.createNewFile();
}
FileWriter fw = new FileWriter( file.getAbsoluteFile() );
BufferedWriter bw = new BufferedWriter( fw );
bw.write( content );
    bw.NewLine();
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}

First name Lastname Registration Number

joe

max

1238

I want to store each data below the its name:

I want to like this:

FName LName Reg_Num

joe max 1238

thanks!

  • 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-16T06:52:02+00:00Added an answer on June 16, 2026 at 6:52 am

    You can use \t to add tab between the fields. The sample code could be something like :

        try {
            String firstName = "Joe";
            String lastName = "Doe";
            String regNum = "123";
    
            File file = new File("/home/parvin/Desktop/filename.txt");
    
            if (!file.exists()) {
                file.createNewFile();
            }
    
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("FirstName\t LastName\t RegNum\t \n");
            bw.write(firstName + "\t" + lastName + "\t" + regNum + "\t" + "\n");
            bw.newLine();
            bw.close();
    
            System.out.println("Done");
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use VB.NET to create data for my game (for Android, Java code), this
I need to download a file using Java. I can use this code to
i am still new to the Java language and libraries... i often use this
I have an opportunity to learn some new tech to write this code. Basic
I'm pretty new to Java ME and i'm trying to use Microlog to handle
How can I authenticate in Java to use the new bing search api from
I'm very new to Java but I've been developing a habit to use final
I am new to java and learning interfaces. I did not understand the use
i m new with netbeans platform , i want to use java class's method
I'm a .NET developer who needs to use the Java platform for a new

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.