相关疑难解决方法(0)

Java Line IO与C++ IO?

请注意,这不是一个"好于"的讨论.

我是一名C++程序员,它让我感到非常愚蠢,不知道如何做很多Java文件IO.

我需要在文件中存储许多不同的数据类型,以便稍后读回.这些包括整数和可变长度的字符串.

在C++中,我可以使用:

//wont actually know the value of this
string mystr("randomvalue");
//the answer to the Ultimate Question of Life, the Universe, and Everything
int some_integer = 42;

//output stream
ofstream myout("foo.txt");
//write the values
myout << mystr << endl;
myout << some_integer << endl;

//read back
string read_string;
int    read_integer;

//input stream
ifstream myin("foo.txt");
//read back values
//how to do accomplish something like this in Java?
myin >> read_string;
myin >> read_integer;
Run Code Online (Sandbox Code Playgroud)

非常感谢!

c++ java file-io

1
推荐指数
1
解决办法
1038
查看次数

标签 统计

c++ ×1

file-io ×1

java ×1