Common method of reading text files, and wrap method in JSP

JAVA in:
package com.action;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.connSql.DAOException;
import com.form.MonitorViewForm;

public class ReadTxtAction extends Action (

public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws DAOException (

MonitorViewForm lf = (MonitorViewForm) form;

System.out.println ("ReadTxtAction");
String findForward = "";
/ **
* Read txt data
* /

String url = "D: / mbfe.log";

lf.setMefe (this.ReadDate (url));

findForward = "sucess";

return mapping.findForward (findForward);
)

/ **
* Read txt data
* /
public String ReadDate (String url) (
try (
FileReader read = new FileReader (new File (url));
StringBuffer sb = new StringBuffer ();
char ch [] = new char [1024];
int d = read.read (ch);
while (d! =- 1) (
String str = new String (ch, 0, d);
sb.append (str);
d = read.read (ch);
)
System.out.print (sb.toString ());
read.close ();
return sb.toString (). trim ();
) Catch (FileNotFoundException e) (
/ / E.printStackTrace ();
return null;
) Catch (IOException e) (
/ / E.printStackTrace ();
return null;
)
)

)

JSP in:
<pre> <bean:write name="monitorViewForm" property="mefe" /> </ pre>

分类:Java 时间:2010-06-28 人气:201
分享到:
blog comments powered by Disqus

相关文章

  • java achieve excel import and export (2) (transfer) 2010-05-02

    ================= ===================== Summary java how to do Excel (data import and export) (change) jxl.jar, can go to http://sourceforge.net/project/showfiles.php?group_id=79926 download. 1. To read the contents of Excel files java code / ** Read

  • java achieve excel import export (1) (transfer) 2010-05-02

    Java data into Excel package com.bossy.base; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import jxl.Workbook; import jxl.format.U

  • Java Oracle Blob import and export Word 2010-12-10

    import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; impor

  • Java code mysql import and export 2011-08-12

    Note mysql import and export must be prepared to achieve good environmental variables, such as: C: \ Program Files \ MySQL \ MySQL Server 5.1 \ bin; otherwise it will not work correctly. package cc.javaweb; import java.io.BufferedReader; import java.

  • java achieve excel import and export (3) (transfer) 2010-05-02

    JAVA EXCEL API Introduction Java Excel is an open source project through which Java developers can read Excel document, create a new Excel file, update an existing Excel file. Non-Windows operating system using the API can also be pure Java applicati

  • SOLR: data import request handler (Data Import Request Handler) 2011-04-24

    http://wiki.apache.org/solr/DataImportHandler Data import request handler (Data Import Request Handler) Solr1.3 Most applications store data in relational databases or XML files and searching over such data is a common use-case. The DataImportHandler

  • Bash string processing (and Java control) - 17 to determine whether the other end of the string 2011-10-09

    Bash string processing (and Java control) - 17 to determine whether the other end of the string In Java String.endsWith oolean endsWith (String suffix) Test whether this string ends with the specified suffix. StringUtils.endsWith & StringUtils.endsWi

  • SQLSERVER import and export text files 2010-06-01

    SQLSERVER import and export text files / ** Export Text File EXEC master .. xp_cmdshell 'bcp "Select * from library name .. table name" queryout c: \ DT.txt-c-S192.168.1.121-Usa-P123456' / ** Import text files EXEC master .. xp_cmdshell 'bcp &qu

  • In excel 2007 to import or export text files _excel tutorial 2011-03-08

    Use Microsoft Office Excel to import data from text files in two ways: to open the text file in Excel, can also be imported as an external data range (external data range: from external to Excel (such as a database or text file) into a worksheet data

  • JAVA operating word reading template files 2010-03-23

    Want to do a java action word of the program, to achieve reading the template file, modify the part, generate a new file such a function. package zb; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOExc

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.689 (s). 10 q(s)