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 7406797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:36:43+00:00 2026-05-29T05:36:43+00:00

package employee; import employee.nidhin.staples; import java.util.*; import java.io.*; public class Employee { public static

  • 0
package employee;

import employee.nidhin.staples;
import java.util.*;
import java.io.*; 



public class Employee {


public static void main(String[] args) 

{
   int j=3;
   staples[] stemp = new staples[j];
  String file_name = "d:/personal/11636470/NetBeansProjects/Employee/src/employee/Xanadu.txt";


 try

 {

 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  

 for ( j=0;j<3;j++)
        {
            stemp[j] = new staples();

            System.out.print("Enter your name : ");
            stemp[j].setName(reader.readLine());

            System.out.println("Enter your age : "); 
            stemp[j].setAge(Integer.parseInt(reader.readLine()));


        }


 for ( j=0;j<3;j++)
        {
            System.out.println("Employee number:" + j +" name:"+stemp[j].getName()+" Age:"+stemp[j].getAge() );

        }




 reader.close(); // VERY IMPORTANT TO CLOSE 

 System.out.println("Now writing the file to Xanadu.txt "); 

  PrintWriter out = new PrintWriter(
  new FileWriter("file_name"));
  for (int i = 0; i < 3; i++) 
  {
       out.println("Value at: "+ i + " = "+ stemp[i].getName());
  }

  System.out.println("Successfully wrote to file");

  out.close();


 }
 catch(java.io.IOException ex)
 {
     System.out.println("Error is " + ex.getMessage() ); 
 }



}   
}

The program execute successfully , but when I open the outputfile Xanadu.txt , I see nothing. Can someone guide me? The contents of the file Xanadu.txt is an array of objects stemp which have two attributes name and age.

  • 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-05-29T05:36:45+00:00Added an answer on May 29, 2026 at 5:36 am
    PrintWriter out = new PrintWriter(new FileWriter("file_name"));
    

    You’re passing a String that says: “file_name”,
    try doing that:

    PrintWriter out = new PrintWriter(new FileWriter(new File(file_name)));
    

    I think it should work. As FileWriter constructor should take File as a parameter, I think.

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

Sidebar

Related Questions

package org.study.algos; public class Study { public static void main(String[] args) { A a
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
package classes.events { import flash.events.Event; public class ASSEvent extends Event { public static const
package samples.flexstore { import flash.events.Event; public class ProductThumbEvent extends Event { public static const
package { import mx.controls.LinkButton; import flash.text.TextLineMetrics; public class multiLineLinkButton extends LinkButton { override protected
package com.crumbin.tabs; //java package import java.io.IOException; import java.util.ArrayList; import org.json.JSONException; import android.app.Activity; import android.app.AlertDialog;
package com.crumbin.tabs; import java.util.ArrayList; import java.util.HashMap; import org.apache.http.client.HttpClient; import android.content.Context; import android.database.Cursor; import android.location.Location;
I have some code copied from the fitness website: package fixtures; import static fitnesse.util.ListUtility.list;

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.