i need to use java to generate and write/append (long)numbers to a text file and use those data for calculation later. can anyone give me a quick reference on what i should use?

i tried:
PrintWriter ---> no writeLong()
RandomAccessFile and BufferedWriter --> give me byte code

i have been googling around and got a bunch of stuff would give me "byte code" in the text (i need the regular text) ... and PrintWriter doesn't have writeLong() method.... Please help.

thanks

Simply write it as a String, and later use Long.parseLong or Long.valueOf to get the long value again.

However, if it is only to write and read longs I don't see why you don't use RandomAcessFile (without wrapping it in a BufferedWriter, it's not meant to be wrapped in anything) to read and write it directly.

Write the primitive data [long data in your case] using DataOutputStream and read the same if required using DataInputStream.

Simply write it as a String, and later use Long.parseLong or Long.valueOf to get the long value again.

However, if it is only to write and read longs I don't see why you don't use RandomAcessFile (without wrapping it in a BufferedWriter, it's not meant to be wrapped in anything) to read and write it directly.

i tried randomAccessFile with bufferedWriter... it gave me byte code to the text... i need to import that text doc to excel for some data process.. so..

i need to use java to generate and write/append (long)numbers to a text file and use those data for calculation later. can anyone give me a quick reference on what i should use?

thanks

You can create a connection stream and chain it to a a chaining stream.

FileWriter writeFile = new FileWriter(File, boolean append);
Buffered writer = new BufferedWriter(writeFile);

writer.write(here goes your long data);

I said without a bufferedwriter.

RandomAccessFile is meant to be used directly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.