Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的文件读写器_Java_File_Text Files - Fatal编程技术网

Java中的文件读写器

Java中的文件读写器,java,file,text-files,Java,File,Text Files,嘿,伙计们,在用java编写文件方面有一个非常基本的问题。我想使用FileWriter.write()函数向文件写入一个长值,但它给出了一个错误。这是密码 accountNos[i] = bA[i].getAccountNo(); fw.write(accountNos[i]); 错误:将accountNos[i]更改为int 但如果我更改它,那么这将意味着信息丢失,我尝试将其转换为字符串,但它表示无法将原语类型long转换为字符串。我做到了: fw.write(accountNos[i].t

嘿,伙计们,在用java编写文件方面有一个非常基本的问题。我想使用FileWriter.write()函数向文件写入一个长值,但它给出了一个错误。这是密码

accountNos[i] = bA[i].getAccountNo();
fw.write(accountNos[i]);
错误:将accountNos[i]更改为int

但如果我更改它,那么这将意味着信息丢失,我尝试将其转换为字符串,但它表示无法将原语类型long转换为字符串。我做到了: fw.write(accountNos[i].toString())

请帮助大家…

使用:


编辑:看起来
accountNos
被声明为
int[]
。将其更改为声明为
long[]

那么您想要什么?Int或String?accountNos[i]=bA[i].getAccountNo();我们不知道它们是什么。@codethulhu我假设左边有一个长数组,
getAccountNo()
是一个长数组,@hexafraction我也会假设,但我不必,我也不会。如果用户懒得问一个质量问题,我就不会浪费时间猜测了。它的声明如下:long accountNos[]=new long[3];还有一件事,当我从文件中读取时,我是否需要将其转换回long,或者它只将帐号存储为long,而读取时也会给出long??实际上,我猜所有文件读取时都只提供字符串格式的数据,您需要将其转换为long
fw.write(Long.toString(accountNos[i]));