Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Convert String in to BigDecimal

807603Nov 20 2007 — edited Nov 21 2007
Hi to all,

I need to convert a file let us say .txt file or .html file in to BigDecimal.
To do this first I will read the file and stored in Byte Array and then converted byte array in to String. There is a Constructor in BigDecimal which accepts String and converts it into BigDecimal but for that String should contains Numeric values but my string contains Characters and symbols can any one provide help regarding this.

Code for Converting File into String is as below.

import java.io.*;
import java.sql.*;
import java.math.*;
public class Test {
public static void main(String[] args)throws IOException
{
try {
String inpName = "index.htm";
File inpFile = new File(inpName);
long lcount = inpFile.length();
int icount = (int) lcount;
InputStream inp = new FileInputStream(inpFile);
int acount = inp.available();
if (icount != acount)
{
System.out.println("all bytes not available");
return;
}
byte[] iobytes = new byte[acount];
int ic = 0;
while (ic < acount)
{
ic += inp.read(iobytes, ic, acount - ic);
}
inp.close();
String sname=new String(iobytes);
System.out.println(sname);


Converting file data into String is working fine but now I have to convert this data in to BigDecimal type.



Thanks in advance,
Durga.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2007
Added on Nov 20 2007
13 comments
1,996 views