Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**
     * Returns the package name of a file that has one of the annotations we are looking for.
     *
     * @return Package prefix string or null or no annotations.
     */
    private static String getPackageOfClass(File file) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        try {
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    return null;
                }
                if (line.contains("package")) {
                    String[] parts = line.split("[ \t;]");
                    if (parts.length > 1 && parts[0].equals("package")) {
                        return parts[1];
                    }
                }
            }
        } finally {
            reader.close();
        }
    }
}