• Post Reply Bookmark Topic Watch Topic
  • New Topic

File System Write  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

I am writing an application in which I need to write into a file some information like:

Master file Account number Name Balance
100 Alan Jones 348.17
300 Mary Smith 27.19
500 Sam Sharp 0.00

One row for each record, again when an user require to access his accounts he may enter his account number and the related records will be fetch, thats why I want to insert each record with the help of row and column.

Here is my code for to write into a file.:

import java.io.*;

class ProgramTest
{
int a_num;
int t_amt;


public static void main(String[] a) throws IOException
{
ProgramTest object = new ProgramTest();

BufferedWriter out=null;

try
{
File file = new File("oldmast.txt");
File file1 = new File("trans.txt");

// Create file if it does not exist

if (file.createNewFile())
{
// File did not exist and was created
System.out.println("oldmast.txt Created Successfully");
}
else
{
System.out.println("oldmast.txt already exists");
}

if (file1.createNewFile())
{
// File did not exist and was created
System.out.println("trans.txt Created Successfully");
}
else
{
System.out.println("trans.txt already exists");
}


TransactionRecord obj=new TransactionRecord();
object=obj.retrieve(object);

out = new BufferedWriter(new FileWriter("oldmast.txt",true));
out.write(String.valueOf(object.a_num));
out.write(String.valueOf(object.t_amt));

}
catch (IOException e)
{
}
finally
{
out.close();
}
}
}



What will I do to use the rows and columns kind of format, please help me out, I am relatively new in the java file system.

please help!

Thanking you all friends.
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i had to insert records like that the i would do something like this


Account number has to be unique so i will take care that it is unique during the entry of the records.

While reading ,i will take each line as a String and check the String whether it contains the account number which has been provided by using the indexOf method
Example:-


If the index is 0 ,then i'll take the record and split up the String using the split method and i'll be able to get each String seperately


result[0]=100
result[1]=Mr A
and so on....

I hope i am able to help you in someway...
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems you are from Mizoram,
And so you are in Java too, thats nice,
Myself holds the same identity,

Ka lawmlu tuk..
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!