corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Java help


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Java help
TheMason66
Member

Registered: 28th Nov 07
Location: Peterborough
User status: Offline
13th Apr 09 at 13:34   View User's Profile U2U Member Reply With Quote

Im having a bit of fun trying to get Vectors to work in Java. Basically, a Vector holds all the information, and i want the program to write all the data into a .txt file at the end, but when the program next starts, it needs to retrieve all the data from the txt file and put it back into the Vector. This essentially overwrites what is in the txt file because there will be a function to delete data from the vector. I can sort of put the data into the txt file, but it retrieves and displays the data as a memory address. If anyone can give me a heads up on how to work the problem out it would be greatly appreciated.
Voyto
Member

Registered: 9th Feb 03
Location: Stafford
User status: Offline
13th Apr 09 at 13:58   View User's Profile U2U Member Reply With Quote

how are you getting the data from the file? A BufferedReader?

[Edited on 13-04-2009 by Voyto]
TheMason66
Member

Registered: 28th Nov 07
Location: Peterborough
User status: Offline
13th Apr 09 at 18:50   View User's Profile U2U Member Reply With Quote

This is how im getting the data into the file::

public void Writer(String Data)
{
PrintWriter writer = null;
try
{
writer = new PrintWriter(new BufferedWriter(new FileWriter("properties.txt")));
writer.println(Data);
writer.close();
}
catch(IOException io)
{
System.out.println("An error has occured");
}
}


And this is what should get it out of the file again:

public static String Reader(String Data)
{
try
{
FileInputStream Fstream = new FileInputStream ("c:\\properties.txt");
DataInputStream Dstream = new DataInputStream(Fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(Dstream));

while((Data = br.readLine()) !=null)
{
System.out.println(Data);
}
Dstream.close();
}
catch(IOException io)
{
System.out.println("An error has occured");
}
return Data;
}

But all im getting is the memory address written into the file.
Voyto
Member

Registered: 9th Feb 03
Location: Stafford
User status: Offline
14th Apr 09 at 09:29   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by TheMason66
This is how im getting the data into the file::

public void Writer(String Data)
{
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter("properties.txt"));
writer.println(Data);
writer.close();
}
catch(IOException io)
{
System.out.println("An error has occured");
}
}


And this is what should get it out of the file again:

public static String Reader(String Data)
{
try
{
FileInputStream Fstream = new FileInputStream ("properties.txt");
DataInputStream Dstream = new DataInputStream(Fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(Dstream));

while((Data = br.readLine()) !=null)
{
System.out.println(Data);
}
Dstream.close();
}
catch(IOException io)
{
System.out.println("An error has occured");
}
return Data;
}

But all im getting is the memory address written into the file.


Ive quoted and edited...try that? Does it write to the file ok now?
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
14th Apr 09 at 10:21   View User's Profile U2U Member Reply With Quote

I never realised how syntactically similar C# and Java are.

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
What Java Compiler Is Standard? Mikorsa16v Geek Day 2 1310
13th Mar 03 at 16:02
by Mikorsa16v
 
How do you use the java multi upload thing jr General Chat 23 1350
25th Jun 06 at 14:35
by Gaz
 
Trouble with Azureus andy1868 Geek Day 8 937
30th Aug 07 at 17:29
by Richie
 

Corsa Sport » Message Board » Off Day » Geek Day » Java help 29 database queries in 0.0101969 seconds