简体   繁体   中英

File reader and Writer in Java

Hey guys have a very basic question in Files writing in java. I want to write a long value to a file using FileWriter.write() function but it gives error. Here is the code

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

Error: change accountNos[i] to 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. I did: fw.write(accountNos[i].toString());

Please help guys...

Use Long.toString() :

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

Edit: It looks like accountNos is declared as int[] . Change it to be declared as long[] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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