0

Need help from you regarding a Scenario, i.e., I have to take a value from DB like "42258258.2300" and convert this into "42,258,258.00" value.

And again need to check whether this value present in downloaded CSV file.

I used below code for read from CSV file but am not getting the output. Kindly help me on this.

String strFile = "outputfile.csv";
FileInputStream fstream = new  FileInputStream(strFile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)   {
String ss = "$42,699,561.00";
if(strLine.contains(ss)){
 System.out.println ("Success"); }
}
in.close();
Test Engg
  • 43
  • 1
  • 1
  • 7
  • Is it possible to provide a few example lines of your CSV file? Without knowing how currencies are formatted in the file I couldn't say why .contains() doesn't find any hit. –  Apr 20 '17 at 14:12
  • Your question is unclear. What is _outputfile.csv_? What does it contain? "42258258.2300", "42,258,258.00" or "$42,699,561.00"? Your code reads all lines of the csv file and expects one of them to contain the 'ss' string, which means one of the lines should contain "$42,699,561.00". – Luciano van der Veekens Apr 20 '17 at 14:31
  • And the fact that you're not seeing a "Success" clearly means the csv file does not contain the dollar string you're looking for. – Luciano van der Veekens Apr 20 '17 at 14:38
  • @luc14n0 outputfile.csv is downloaded file from site. that will contain some values $42,699,561.00 like this. Yes one of the lines contain this value. file contains this value i dont know how to attach file here sorry – Test Engg Apr 21 '17 at 07:47

1 Answers1

0

What do you get if you print strLine? Are you really getting the string?

This code works for me

public void getFileInformation(){
        String strFile = "/Users/myUser/Documents/outputfile.csv";
        BufferedReader br = null;
        String strLine = "";
        String ss = "$42,699,561.00";           
        try {
            br = new BufferedReader(new FileReader(strFile));                
            while ((strLine= br.readLine()) != null) {
                if(strLine.contains(ss)){
                    System.out.println ("Success"); 
                }else{
                    System.out.println (strLine);
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                 } catch (IOException e) {
                    e.printStackTrace();
                 }
            }
        }
    }

But the content "$42,699,561.00"; should really exist in the file

  • hi @Jose Pedroza executed the script but prints else statement even that "$42,699,561.00" value present. But when i execute with "$" this gives "Success". I dont know why can you help me ? – Test Engg Apr 21 '17 at 12:11
  • So sorry, I were out all weekend, if you still have the doubt I'll try to help you now, when you say "when i execute with "$" this gives "Success"" where are you using the "$" in the file or in the String? – Jose Pedroza Apr 24 '17 at 19:11
  • thats ok . in file am checking "$42,699,561.00" value but that was not getting execute :( – Test Engg May 03 '17 at 14:12