Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. How to found a file by utilizing a variable for 'Startswith' in JAVA?

How to found a file by utilizing a variable for 'Startswith' in JAVA?

Scheduled Pinned Locked Moved Java
javaapachehelptutorialquestion
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MOHAMMAD ZAINUL ABIDEEN
    wrote on last edited by
    #1

    I'm trying to find a file based on the starting eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using the code below and still appears to be fresh, so I don't know how to correct this, Even after it happen to be a straightforward repair.

    package Chrome;
    //CHROME
    import java.io.File;
    import java.io.FileFilter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FilenameFilter;

    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.DataFormatter;
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;

    public class ValidateInput {

    public static void main(String[] args) throws Throwable {
    // TODO Auto-generated method stub

    // String filePath=System.getProperty("user.dir")+"\\UP.xlsx";
    //File src = new File(filePath);
    //System.out.println(filePath);
    File src = new File("C:\\Users\\Z246379\\Documents\\TestDataFolder\\ValidateInput.xlsx");
    FileInputStream fis = new FileInputStream(src);

    XSSFWorkbook wb = new XSSFWorkbook(fis);
    XSSFSheet Sheet1 = wb.getSheetAt(0);
    int i1 = 2;
    //Username
    String data0 = Sheet1.getRow(2).getCell(0).getStringCellValue();
    //Password
    String data01 = Sheet1.getRow(2).getCell(1).getStringCellValue();
    //Case ID
    String caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
    // Description
    String Desc = Sheet1.getRow(2).getCell(3).getStringCellValue();
    //Internal Claim File
    String ICF = Sheet1.getRow(1).getCell(4).getStringCellValue();
    String CRPT = Sheet1.getRow(1).getCell(5).getStringCellValue();

    // final String caseID1 = caseID1;

    //Chrome driver code

    System.out.println("Called openBrowser");
    String exePath = System.getProperty("user.dir")+"\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);
    options.addArguments("start-maximized");
    options.addArguments("--no-sandbox");
    options.addArguments("--disable-extensions-except");
    options.addArguments("disable-extensions");
    //options.setE

    L 1 Reply Last reply
    0
    • M MOHAMMAD ZAINUL ABIDEEN

      I'm trying to find a file based on the starting eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using the code below and still appears to be fresh, so I don't know how to correct this, Even after it happen to be a straightforward repair.

      package Chrome;
      //CHROME
      import java.io.File;
      import java.io.FileFilter;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.FilenameFilter;

      import org.apache.poi.ss.usermodel.Cell;
      import org.apache.poi.ss.usermodel.DataFormatter;
      import org.apache.poi.xssf.usermodel.XSSFCell;
      import org.apache.poi.xssf.usermodel.XSSFSheet;
      import org.apache.poi.xssf.usermodel.XSSFWorkbook;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.chrome.ChromeOptions;

      public class ValidateInput {

      public static void main(String[] args) throws Throwable {
      // TODO Auto-generated method stub

      // String filePath=System.getProperty("user.dir")+"\\UP.xlsx";
      //File src = new File(filePath);
      //System.out.println(filePath);
      File src = new File("C:\\Users\\Z246379\\Documents\\TestDataFolder\\ValidateInput.xlsx");
      FileInputStream fis = new FileInputStream(src);

      XSSFWorkbook wb = new XSSFWorkbook(fis);
      XSSFSheet Sheet1 = wb.getSheetAt(0);
      int i1 = 2;
      //Username
      String data0 = Sheet1.getRow(2).getCell(0).getStringCellValue();
      //Password
      String data01 = Sheet1.getRow(2).getCell(1).getStringCellValue();
      //Case ID
      String caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
      // Description
      String Desc = Sheet1.getRow(2).getCell(3).getStringCellValue();
      //Internal Claim File
      String ICF = Sheet1.getRow(1).getCell(4).getStringCellValue();
      String CRPT = Sheet1.getRow(1).getCell(5).getStringCellValue();

      // final String caseID1 = caseID1;

      //Chrome driver code

      System.out.println("Called openBrowser");
      String exePath = System.getProperty("user.dir")+"\\chromedriver.exe";
      System.setProperty("webdriver.chrome.driver", exePath);
      ChromeOptions options = new ChromeOptions();
      options.setExperimentalOption("useAutomationExtension", false);
      options.addArguments("start-maximized");
      options.addArguments("--no-sandbox");
      options.addArguments("--disable-extensions-except");
      options.addArguments("disable-extensions");
      //options.setE

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try this:

      final String caseId1 = caseID; // add this final variable
      FilenameFilter filter = new FilenameFilter() {
      public boolean accept (File dir, String name) {
      return name.startsWith(caseId1); // use the final variable here
      }
      };

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups