社区
Web 开发
帖子详情
如何生成TXT文件?
XmanYZ
2003-08-18 03:09:39
在我的页面上,设置个按钮,点击按钮能生成txt文件?
...全文
134
12
打赏
收藏
如何生成TXT文件?
在我的页面上,设置个按钮,点击按钮能生成txt文件?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
12 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
fuzhan820
2003-09-06
打赏
举报
回复
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.io.*" %>
<%
String fileName = "zsc104.swf".toString();
//读到流中
InputStream inStream=new FileInputStream("c:/zsc104.swf");
//设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
//循环取出流中的数据
byte[] b = new byte[100];
int len;
while((len=inStream.read(b)) >0)
response.getOutputStream().write(b,0,len);
inStream.close();
%>
fuzhan820
2003-09-06
打赏
举报
回复
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import="DBstep.iDBManager2000.*"%>
<%
int bytesum=0;
int byteread=0;
//打开数据库
ResultSet result=null;
String Sql=null;
PreparedStatement prestmt=null;
DBstep.iDBManager2000 DbaObj=new DBstep.iDBManager2000();
DbaObj.OpenConnection();
//取得数据库中的数据
Sql="select * from t_local_zhongzhuan ";
result=DbaObj.ExecuteQuery(Sql);
result.next();
将数据库中的数据读到流中
InputStream inStream=result.getBinaryStream("content");
FileOutputStream fs=new FileOutputStream( "c:/dffdsafd.doc");
byte[] buffer =new byte[1444];
int length;
while ((byteread=inStream.read(buffer))!=-1)
{
out.println("<DT><B>"+byteread+"</B></DT>");
bytesum+=byteread;
System.out.println(bytesum);
fs.write(buffer,0,byteread);
}
%>
stonewang
2003-08-19
打赏
举报
回复
XmanYZ(司徒游龙) :
1、byte[] b = str.getBytes();--得到传入的str字符串,作为文件的内容(如:"i'm a boy")
2、url--------------------------创建文件的全路径(如:"d:/temp/aFile.txt")
allan1031
2003-08-19
打赏
举报
回复
生成在本地?关注~~~~
ticlej
2003-08-18
打赏
举报
回复
你把文本传回服务器,然后用 yuanz62提供的方法写道文件就可以了.
如果是写到客户端,建议你还是直接从服务器上下载比较好.否则涉及到一堆安全之类的问题.
public 中返回的是什么样的东西?
你指得是public static void main(String[] args) throws IOException这个方法吗?
他不返回任何信息.要不生成文件成功,要么throw exception
XmanYZ
2003-08-18
打赏
举报
回复
我是菜鸟
byte[] b = str.getBytes();
这句不懂
还有就是存盘路径是不是就是url?
stonewang
2003-08-18
打赏
举报
回复
1、生成txt
public static void testWrite(String str,String url)
{
FileOutputStream out;
try {
out = new FileOutputStream(url);
byte[] b = str.getBytes();
out.write(b);
}
catch (Exception e) {
e.printStackTrace();
}
}
(jdk1.4通过)
2、如果是在跑ie的applet,请加数字签名(不清楚可以问我)
XmanYZ
2003-08-18
打赏
举报
回复
文本内容不是定义好的
是从页面上传到后台的
通过按钮来调用javabean
public 中返回的是什么样的东西?
Leemaasn
2003-08-18
打赏
举报
回复
可以使用服务器生成,通过下载到本地
XmanYZ
2003-08-18
打赏
举报
回复
在本地生成TXT呢?
luo_wen_jie
2003-08-18
打赏
举报
回复
但txt文件是在服务器端生成的
yuanz62
2003-08-18
打赏
举报
回复
public static void main(String[] args) throws IOException
{
File outputFile=new File("d:\\zhyuan\\Dst.txt");
FileOutputStream out=new FileOutputStream(outputFile);
String c="abcdefg....";
out.write(c);
out.close();
}
C#
生成
Txt
文件
问题:如果
生成
Txt
文件
? 解决: string P_str_path = "C:\\1.
txt
"; StreamWriter sw = new StreamWriter(P_str_path,false); sw.WriteLine("0001879"); sw.Close(); 转载于:ht...
Java
生成
txt
文件
,
生成
zip
文件
公司的需求一如既往地奇葩,要求后台将一段String字符串
生成
txt
文件
,并且同一个word
文件
一起打包成zip压缩包。干嘛用呢?外网要将简报信息导入内网,
txt
文件
用于存储简报信息和内容,word
文件
是简报信息上传的附件,一起压缩成zip
文件
,让服务手动传到内网。 话不多说上代码 > > /** *网络舆情栏目 * musicInfo:需要
生成
txt
文...
Java
生成
txt
文件
Java
生成
txt
文件
PHP
生成
txt
文件
1. 案例1: file_put_contents("c:/lth/zll.
txt
","这是我
生成
的
txt
文件
"); 注意:确保路径 正确,后面的 zll.
txt
是设置的
文件
名字, 然后后面 是内容; 2.案例2: $myfile = fopen("c:/new.
txt
", "a") or die("Unable to open file!"); $b="这是我案例二
生成
的
文件
"; fwrite($myfile, $b);//写入内容,可以写多次哦,不过没啥意义,因为你拼
QT--读取/
生成
txt
文件
本文为学习记录,若有错误,请联系作者,谦虚受教。 文章目录前言一、
生成
txt
文件
1..h
文件
2..cpp
文件
总结 前言 你看我越是穷途末路 就越是势如破竹. 一、
生成
txt
文件
1…h
文件
在头
文件
中需要添加QFile头
文件
#include<QFile> #include<QTextStream> #include<QFileDialog> // QTextStream是一个非常强大的类,它可以对IO设备,QString,QByteArray等类进行方便的读写操作
Web 开发
81,094
社区成员
341,711
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章