Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Write username and password into file  RSS feed

 
Slaxmi Raj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
class Example {
String user_Name;
String password;
Example(String user_Name,String password)
{
this.user_Name=user_Name;
this.password=password;

}
void write_File()
{
try
{
BufferedWriter out=new BufferedWriter(new FileWriter("example2.txt"));

out.write(user_Name);
out.write(password);
out.close();
}catch(IOException e)
{}

}
}

public class ExampleDemo {
public static void main(String[] args) {
Example e=new Example("user1","abcd");
e.write_File();
Example e1=new Example("user2","efgh");
e1.write_File();
}

}
Hi,
Here are two calsses,Example and ExampleDemo, i would like to write username and password into a text file,i wrote the usernames and passwords by using write(String args) method.
it was successfully written into text file,, but when i saw in the text file , there is one username and password only(that is -user2efgh). where is the user1abcd?. i did not understand where it was went.
please any one tell me how to write two usernames and passwords into a text file.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Switch the example objects around in your code, execute it again and check the text file. Hopefully, that output will give you a better idea of what is going on.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!