简体   繁体   English

Java中的文件阅读器和Writer

[英]File reader and Writer in Java

Hey guys have a very basic question in Files writing in java. 嘿伙计们在用java编写的文件中有一个非常基本的问题。 I want to write a long value to a file using FileWriter.write() function but it gives error. 我想使用FileWriter.write()函数向文件写一个long值,但它给出了错误。 Here is the code 这是代码

accountNos[i] = bA[i].getAccountNo();
fw.write(accountNos[i]);

Error: change accountNos[i] to int. 错误:将accountNos [i]更改为int。

But if I change it then it would mean a loss of information and I tried converting it String but it says it cannot convert primitive type long to string. 但是,如果我改变它然后它将意味着丢失信息,我尝试将其转换为String但它说它不能将原始类型long转换为字符串。 I did: fw.write(accountNos[i].toString()); 我做了:fw.write(accountNos [i] .toString());

Please help guys... 请帮帮我们......

Use Long.toString() : 使用Long.toString()

fw.write(Long.toString(accountNos[i]));

Edit: It looks like accountNos is declared as int[] . 编辑:看起来accountNos被声明为int[] Change it to be declared as long[] . 将其更改为声明为long[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM