I have a program that converts Excel to CSV and I used 2 ways to do this: one of them uses CsvWriter write and the other program uses BufferedWriter write but the problem that I have encountered here is in order to write an Integer to a file you need to convert it to string with
String.valueOf(myInt);
but I need a pure Integer not a string because when I am trying to upload this file in Oracle database it throws me
Ora-01722 invalid number exception
I tried to create a CSV file from my Windows and Oracle works perfectly fine with that data.
So my question is there a way to write an Integer not a String to a file? Any help?
解决方案
Use DataOutputStream Object to write primitive int value to a file.
Example:
//create FileOutputStream object
FileOutputStream fos = new FileOutputStream(strFilePath);
/*
* To create DataOutputStream object from FileOutputStream use,
* DataOutputStream(OutputStream os) constructor.
*/
DataOutputStream dos = new DataOutputStream(fos);
int i = 100;
/*
* To write an int value to a file, use
* void writeInt(int i) method of Java DataOutputStream class.
*
* This method writes specified int to output stream as 4 bytes value.
*/
dos.writeInt(i);
/*
* To close DataOutputStream use,
* void close() method.
*
*/
dos.close();