社区
Java SE
帖子详情
怎么取得文件类型如:text/html
butnet
2006-08-26 11:38:57
请问:怎么取得文件类型如:text/html
...全文
382
10
打赏
收藏
怎么取得文件类型如:text/html
请问:怎么取得文件类型如:text/html
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jayfantsy
2006-10-04
打赏
举报
回复
楼上,我看不懂啊..菜鸟难啊..
butnet
2006-10-03
打赏
举报
回复
/**
*我的解决办法
*FileType.java
*/
package FileType;
import java.io.*;
public class FileType
{
FileReader f;
BufferedReader in;
String trueEnd;
public FileType(String End) throws Exception
{
try{
f=new FileReader("alltype.txt");
in=new BufferedReader(f);
trueEnd=End;
}catch(Exception e){Error.error("初始化mail.FileType类失败"+e);throw new Exception();}
}
public String findType() throws Exception
{
try{
String type="application/octet-stream";
String tempType=null;
String end="";
while(true)
{
tempType=readType();
if(tempType==null)return type;
end=readEnd();
if(end.compareTo(trueEnd)==0)return tempType;
}
}catch(Exception e){Error.error("mail.FileType.findType()出错:"+e);return null;}
}
private String readType() throws Exception
{
try{
do{
String line=new String("");
line=in.readLine();
if(line==null)return null;
if(line.indexOf("/")!=-1)
{
line=line.substring(line.lastIndexOf("\\")+1);
line=line.substring(0,line.length()-1);
return line;
}
}while(true);
}catch(Exception e){Error.error("mail.FileType.readType()出错:"+e);return null;}
}//readType
private String readEnd() throws Exception
{
try{
String line=new String("");
do{
line=in.readLine();
if(line==null)return null;
if(line.indexOf(".")!=-1)
{
line=line.substring(line.lastIndexOf("."));
line=line.substring(0,line.length()-1);
return line;
}
}while(true);
}catch(Exception e){Error.error("mail.FileType.readEnd()出错:"+e);return null;}
}//readEnd
}
/**
*getAllFileType.java
*/
package FileType;
import java.io.*;
class getAllFileType{
BufferedReader in;
BufferedWriter out;
public getAllFileType() throws Exception
{
start();
}
private void start() throws Exception
{
try{
FileWriter bat=new FileWriter("IntToChar.bat");
out=new BufferedWriter(bat);
out.write("type temptype.txt>alltype.txt\r\ndel temptype.txt\r\ndel IntToChar.bat");
out.close();
bat.close();
Runtime runThread=Runtime.getRuntime();
Process childTh=runThread.exec("regedit /e temptype.txt \"HKEY_CLASSES_ROOT\\MIME\\Database\\Content Type\"");
childTh.waitFor();
childTh=runThread.exec("IntToChar.bat");
childTh.waitFor();
FileReader f=new FileReader("alltype.txt");
in=new BufferedReader(f);
FileWriter f1=new FileWriter("All Types.txt");
out=new BufferedWriter(f1);
while(true)
{
String w=readType();
if(w==null){in.close();out.close();return;}
out.write(w);
w=readEnd();
if(w==null){in.close();out.close();return;}
out.newLine();
out.write(w);
out.newLine();
}
}catch(Exception e){Error.error("mail.getAllFileType.start()出错:"+e);}
}
private String readType() throws Exception
{
try{
do{
String line=new String("");
line=in.readLine();
if(line==null)return null;
if(line.indexOf("/")!=-1)
{
line=line.substring(line.lastIndexOf("\\")+1);
line=line.substring(0,line.length()-1);
return line;
}
}while(true);
}catch(Exception e){Error.error("mail.getAllFileType.start()出错:"+e);return null;}
}//readType
private String readEnd() throws Exception
{
try{
String line=new String("");
do{
line=in.readLine();
if(line==null)return null;
if(line.indexOf(".")!=-1)
{
line=line.substring(line.lastIndexOf("."));
line=line.substring(0,line.length()-1);
return line;
}
}while(true);
}catch(Exception e){Error.error("mail.getAllFileType.start()出错:"+e);return null;}
}
}
/*
方法很笨!但总算搞定!
*/
butnet
2006-08-27
打赏
举报
回复
我的意思是:
不用servlet
是在JDK下
怎么取Content Type
wjs2338
2006-08-26
打赏
举报
回复
楼主的意思应该是servlet中有什么方法可以得到contentType这个内容,我想应该是有方法可以得到的,但是我不知道。
javajiao
2006-08-26
打赏
举报
回复
去查阅相关HTTP报表表头那不分内容
里面有涉及
我记的在《servlet与jsp核心编程开发》里有
你可以去看看
zhangj0571
2006-08-26
打赏
举报
回复
莫非是 用正则表达式去模式匹配???
butnet
2006-08-26
打赏
举报
回复
不是在tomcat下.
我是用的jdk
请问,你知道吗?
liujin4049
2006-08-26
打赏
举报
回复
如果是tomcat的话,在conf/web.xml里有,可以去读
butnet
2006-08-26
打赏
举报
回复
不是那个意思.
不是从文件名分析.
而是从文件内容
例如:
微软的幻灯片
类型为:application/vnd.ms-powerpoint
meadking
2006-08-26
打赏
举报
回复
根据文件名后缀
基于Web的酒店客房管理系统的设计与实现+论文+开题
MediaType mediaType = new MediaType("
text
", "
html
", Charset.forName("utf-8")); headers.setContentType(mediaType); return headers; } /** * 返回 信息数据 * * @param status * @param msg * @return */ ...
data:
text
/
html
;c,
html
image -- data:image/png;base64
直接嵌入到网页中,从而不用再从外部文件加载。比方上面那串字符,事实上是一张小图片。将这些字符复制黏贴到火狐的地址栏中并转到,就能看到它了,一张1X36的白灰png图片。在上面的Data URI中。data表...
写web项目时出现的错误:来自“http://localhost:63342/Demo/test01/day0618/css/a.css”的资源已被阻止,因为 MIME 类型(“
text
/
html
”)
来自“http://localhost:63342/Demo/test01/day0618/css/a.css”的资源已被阻止,因为 MIME 类型(“
text
/
html
”)不匹配(X-Content-Type-Options: nosniff) 外部引入的css文件不能作用于
html
标签上 解决方法:在...
content-Type:
text
/plain和
text
/
html
最近再看nodejs 建立服务的时候: var http = require("http"); +http.createServer(function (request, ...+ response.writeHead(200, {"Content-Type": "
text
/plain"}); + response.write("Hello
编码 data:
text
/
html
;c,javascript中Data URI使用详解
Data URI,不是URLURL是uniform resource locator的缩写,在web中的每一个可访问资源都有一个URL地址,例如图片,
HTML
文件,js文件以及style sheet文件,我们可以通过这个地址去download这个资源。其实URL是URI的...
Java SE
62,614
社区成员
307,327
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章