Hey,
Does anyone know how to read
and write to text files in Java?
In C++, to read a file, you would do:
(stores the contents into array "data"
In C++, to write to a file, you would do:
(writes "Hello, world!" to myFile.txt)
Anyone have the Java equivalent?
Thanks,
Steve.
Does anyone know how to read
and write to text files in Java?
In C++, to read a file, you would do:
(stores the contents into array "data"
Code:
ifstream f("myFile.txt")
char ch;
char* data = " ";
while (f.get(ch))
{
data << ch;
}
f.close();
In C++, to write to a file, you would do:
(writes "Hello, world!" to myFile.txt)
Code:
ofstream g("myFile.txt");
g << "Hello, world!" << "\n";
g.close();
Anyone have the Java equivalent?
Thanks,
Steve.