Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

public class Main {
    public static int findNextSequence(String path, String seqFileNamePrefix, String seqFileNameSuffix) {
        int seq = 0;
        File[] child = null;
        try {
            File dir = new File(path);
            child = dir.listFiles();
        } catch (Exception e) {
            child = null;
        }

        if (child == null) {
        } else {
            for (int i = 0; i < child.length; i++) {
                String fileName = child[i].getName();
                int pre = fileName.indexOf(seqFileNamePrefix) + seqFileNamePrefix.length();
                int suf = fileName.lastIndexOf(seqFileNameSuffix);
                int sufLen = seqFileNameSuffix.length();
                String val_s = "";

                try {
                    int val = 0;
                    if ((pre >= 0) && (suf >= 0) && (suf > pre) && ((suf + sufLen) == fileName.length())) {
                        val_s = fileName.substring(pre, suf);
                        val = Integer.parseInt(val_s);
                    }
                    if (val > seq)
                        seq = val;
                } catch (Exception e) {
                }
            }

        }
        return seq + 1;
    }
}