ukapu2005
asked on
please provide me the java code to write into a file and then I should able to read that info from file
I want to write the following info onto a file that is located in my d drive. Can any body provide me the java code.
CUSTORDR - "13007","","","0.0","C"
ORDERDET - "12002","item1d","1.0","10 0.0","100. 0"
ORDERDET - "11503","item1b","1.0","10 0.0","100. 0"
ORDERDET - "11503","item1b","4.0","10 0.0","400. 0"
SHIPCHRG - "0.0","0"
SALESTAX - "0.0","0.0"
CUSTORDR - "13007","","","0.0","C"
ORDERDET - "12002","item1d","1.0","10
ORDERDET - "11503","item1b","1.0","10
ORDERDET - "11503","item1b","4.0","10
SHIPCHRG - "0.0","0"
SALESTAX - "0.0","0.0"
http://javaalmanac.com/egs/java.io/WriteToFile.html
So that's:
try {
BufferedWriter out = new BufferedWriter(new FileWriter("d:/dir1/MyFile .txt"));
out.write("theLineyouWant1 ");
out.write("theLineyouWant2 ");
out.write("theLineyouWant3 ");
out.write("theLineyouWant4 ");
out.write("theLineyouWant5 ");
out.close();
} catch (IOException e) {
}
try {
BufferedWriter out = new BufferedWriter(new FileWriter("d:/dir1/MyFile
out.write("theLineyouWant1
out.write("theLineyouWant2
out.write("theLineyouWant3
out.write("theLineyouWant4
out.write("theLineyouWant5
out.close();
} catch (IOException e) {
}
String s = ...(whatever You need)
//writing to file
FileOutputStream fout = new FileOutputStream("D:\filen ame");
fout.write(s.getBytes());
fout.close();
//reading
FileInputStream fin = new FileInputStream("D:\filena me");
byte[] contents = new byte(fin.available());
fin.read(contents);
String s = new String(contents);
//writing to file
FileOutputStream fout = new FileOutputStream("D:\filen
fout.write(s.getBytes());
fout.close();
//reading
FileInputStream fin = new FileInputStream("D:\filena
byte[] contents = new byte(fin.available());
fin.read(contents);
String s = new String(contents);
If you want your file exactly to contain the line
CUSTORDR - "13007","","","0.0","C"
then use
out.write("CUSTORDR - \"13007\",\"\",\"\",\"0.0\ ",\"C\"");
CUSTORDR - "13007","","","0.0","C"
then use
out.write("CUSTORDR - \"13007\",\"\",\"\",\"0.0\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, zzynx You're right :)
This question seems to be popular because it's asked more that once.
From which book?
;JOOP!
From which book?
;JOOP!
Thanks for accepting.
(For the future: If you're not completely satisfied with a comment - that's how I interprete a B-grade - you can always ask for further explanation)
(For the future: If you're not completely satisfied with a comment - that's how I interprete a B-grade - you can always ask for further explanation)