⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpcheckfile.java

📁 简介: 今天为网友提供的是JAVA源码
💻 JAVA
字号:
package com.power.pipeengine;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class LPCheckFile extends HttpServlet{//extends HttpServlet{
    public String _str = "";

    /**
     * Process incoming HTTP GET requests
     *
     * @param request Object that encapsulates the request to the servlet
     * @param response Object that encapsulates the response from the servlet
     */
    public void doGet(
        javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response)
        throws ServletException, IOException {
        doPost(request,response);
		System.out.println("Nothing to do when GET method.");
    }
    /**
     * Process incoming HTTP POST requests
     *
     * @param request Object that encapsulates the request to the servlet
     * @param response Object that encapsulates the response from the servlet
     */
    public void doPost(
        javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response)
        throws ServletException, IOException {

        /**** Initialize Writer ****/
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        response.setStatus(HttpServletResponse.SC_OK);
        String _FileName = request.getParameter("FileName");
        String _LogPath = request.getParameter("LogPath");

        /**** Check File Exists ****/
        System.out.println("Check File exists --> " + _FileName);
        RandomAccessFile ccc = null;
        try {
            ccc = new RandomAccessFile(_FileName,"r");
            out.println(ccc.length()>1?"found":"not found");

            //clear Log File
            if (_LogPath != null && ccc.length()>1) {
                File file = new File(_LogPath);
                while (!file.exists() || file.length()==0) {}
                System.out.println("Clear Log file -->  "+_LogPath + " " +
                                   (file.delete()?"OK":"failed."));
            }
        }
        catch (FileNotFoundException ex) {
            out.println("not found");
        }
        finally {
            if (ccc != null ) ccc.close();
        }
        System.out.println();
    }
    /**
     * Returns the servlet info string.
     */
    public String getServletInfo() {
        return super.getServletInfo();
    }
    /**
     * Called whenever the part throws an exception.
     * @param exception java.lang.Throwable
     */
    private void handleException(java.lang.Throwable exception) {
        System.out.println("--------- UNCAUGHT EXCEPTION ---------");
        exception.printStackTrace(System.out);
    }
    /**
     * Initializes the servlet.
     */
    public void init(ServletConfig config) throws ServletException {
        // insert code to initialize the servlet here
        super.init(config);
    }
    /**
     * Initialize the class.
     */
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
        try {
        } catch (java.lang.Throwable ivjExc) {
            handleException(ivjExc);
        }
    }

    /**
     * Process incoming requests for information
     *
     * @param request Object that encapsulates the request to the servlet
     * @param response Object that encapsulates the response from the servlet
     */
    public void performTask(
        javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response) {
        //System.out.println("performTask() method is called.");
    }
    /**
     * service method comment.
     */
    public void service(HttpServletRequest request, HttpServletResponse response)
        throws javax.servlet.ServletException, java.io.IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String sMethod;
        sMethod = request.getMethod();
        if (sMethod.equals("GET"))
            doGet(request, response);
        else
            doPost(request, response);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -