TheMason66
Member
Registered: 28th Nov 07
Location: Peterborough
User status: Offline
|
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
|
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
|
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
|
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
|
I never realised how syntactically similar C# and Java are.
|