R
R
roman38472014-04-03 18:33:00
Java
roman3847, 2014-04-03 18:33:00

Organizing Search in a Java String

Example file to open: 123abcd55ui
I'm reading data from a file into the ch array.

char ch[] = new char[(int) file.length()];
    
        int i =0;
       
        if (!(file.isFile() && file.canRead())) {
          System.out.println(file.getName() + " cannot be read from.");
          return;
        }
        try {
          FileInputStream fis = new FileInputStream(file);
          char current;
          while (fis.available() > 0) {
            current = (char) fis.read();
            ch[i] = current; i++;
            //System.out.print(current);
          }
        } catch (IOException e) {
          e.printStackTrace();
        }

And then I need to find out if there is a substring in my array (3ab for example). Can this be done for a char array, and if so, how?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question