Chinaunix首页 | 论坛 | 博客

acc

  • 博客访问: 791654
  • 博文数量: 170
  • 博客积分: 7011
  • 博客等级: 少将
  • 技术积分: 1660
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-31 12:02
文章分类

全部博文(170)

文章存档

2014年(7)

2010年(2)

2009年(62)

2008年(25)

2007年(67)

2006年(7)

我的朋友

分类: Java

2007-10-28 15:18:52

//写文件

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.io.*"%>
<%
    Random random = new Random();
        String sRand="";
        int j=0;
       String outPut ="D:\\acc\\";
       StringBuffer ab = new StringBuffer();
               for(j=1;j<=10;j++){
            
            for (int i=0;i<6;i++){
            String rand=String.valueOf(random.nextInt(10));
            sRand+=rand;
            }
            ab.append(sRand+"\n");
            sRand="";
        }
        
       try{
       File temp = new File(outPut,"random.txt");
       DataOutputStream outs = new DataOutputStream(
               new FileOutputStream(temp));
       outs.write(ab.toString().getBytes());
       outs.close();
       }catch(Exception e){
           e.printStackTrace();
       }
%>

 

//读文件

 

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*"%>
<%
  try{
  //取得当前目录路径

  String strPath = request.getRealPath("");
  //建立FileReader对象

  FileReader fr = new FileReader(strPath + "\\scroll.txt");
  //建立BufferedReader对象

  BufferedReader br = new BufferedReader(fr);
  //从文件读取一行字符串

  String Line = br.readLine();

  //判断读取到的字符串是否不为空

  String strNews = "";
  while(Line != null){
    strNews += Line + "
"
;
    Line = br.readLine();
  }
  br.close();
  fr.close();
%>
<html>
<head>
<title>
读取滚动新闻
</title>
</head>
<body bgcolor="#ffffff">
<marquee style="color:#000000;font-size:12px;line-height:20px;" direction="up" height="70" scrollamount="1" scrolldelay="100" onMouseOver="this.scrollDelay=500" onMouseOut="this.scrollDelay=1">
<%=strNews%>
</marquee>
</body>
</html>
<%
  }catch(Exception e){
    e.printStackTrace();
  }
%>

阅读(1377) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~