1
FileInputStream input=new FileInputStream(new File("C:\\Report\\TestCase.xls"));
HSSFWorkbook workbook=new HSSFWorkbook(input);
HSSFSheet sheet=workbook.getSheet("KeywordFramework");
System.out.println("i am in");

How can i make my path a relative path ? Example (..\..\TestCase.xls) It should search the file in system and call it , is the requirement

HSSFWorkbook workbook=new HSSFWorkbook(input);
  ExpectedOP=Cellvalue;
    int LastRow = 1;
        for(int i1=1;i1<5;i1++)
        {
        String sr [] =new String [10];
        sr[i1]=driver.findElement(By.xpath(".//*[@id='stepList']/li["+i1+"]")).getText();
        System.out.println("UserID = "+sr[i1]);
        for (int j1=1;j1<sr.length;j1++)
            {
            if(ExpectedOP.equals(j1))
            {
                System.out.println("compare pass");
                String status="PASS";
                Row row1 = sheet.getRow(LastRow);

                Cell cell2 = row1.createCell(18);
                cell2.setCellValue(status);
                System.out.println(status);

                input.close();
                FileOutputStream outFile =new FileOutputStream(new File("TestCase.xls"));
                workbook.write(outFile);
            }
            else
            {
            System.err.println("compare fail");
            String status = "FAIL";
            Row row1 = sheet.getRow(LastRow);

            Cell cell2 = row1.createCell(18);
            cell2.setCellValue(status);
            System.out.println(status);

            input.close();
            FileOutputStream outFile =new FileOutputStream(new File("TestCase.xls"));
            workbook.write(outFile);
            }
            }
        }

This is my code to compare value from website and excel and here am telling IDE to place the pass/fail result in cell number 18 , which i want to make dynamic and also in "i1<5" "5" should be removed and made dynamic which number of cell counts Thank you

8
  • Refer this : stackoverflow.com/questions/18226434/… Commented Dec 3, 2014 at 6:38
  • This is not a Selenium problem! This is a pure Java problem finding a file in the system. Commented Dec 3, 2014 at 6:42
  • Hi Helping Hands , i went to the link you have referred me to i got the path of the file using the code suggested , but poi considers path as (example : C//123//test.xls) Code suggested there gives path in normal way that is , C/123/test.xls , is there anyway i can fix this ? Commented Dec 3, 2014 at 6:48
  • POI can consider path like D:\\data.xls Commented Dec 3, 2014 at 6:54
  • yes , you can observe in the code attached to my question above for reference :) , is there anyway i can change "\" in path to "\\" ? Commented Dec 3, 2014 at 6:54

2 Answers 2

0

Can you try like :

 FileInputStream input=new FileInputStream(new File("TestCase.xls"));

In your code? I think it should work.

Sign up to request clarification or add additional context in comments.

Comments

0

As long as you pass a valid FileInputStream to POI you can use any valid file path you want to open the workbook. So the following code should work fine:

FileInputStream input=new FileInputStream(new File("../../TestCase.xls"));
HSSFWorkbook workbook=new HSSFWorkbook(input);
HSSFSheet sheet=workbook.getSheet("KeywordFramework");
System.out.println("i am in");

2 Comments

An IOException was caught! java.io.FileNotFoundException: ..\..\TestCase.xls (The system cannot find the file specified) This is the error i am getting , where as TeastCase.xls is present in the same folder where the code is
Please check what your current working directory is. The code above will look for a file relative to this working directory. When running a maven project for example it is not the directory where your source files are but the root directory of the project. To get your working directory you can try: File workingDir = new File(""); System.out.println("Working directory is: " + workingDir.getAbsolutePath());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.