csdn代码格式化

对于以上的代码样式,想必大家非常熟悉,下面给出一个参考示例:

<%@page import="java.io.InputStream"%>
<%@page import="com.baiyang.lc.util.FileUtil"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String docRoot = System.getProperty("docRoot");
	String file = request.getParameter("path");
	String type = file.substring(file.lastIndexOf(".") + 1)
			.toLowerCase();
	if (type == "cs") {
		type = "CSharp";
	} else if ("txt".equals(type)) {
		type = "plain";
	}
	String brush = type;
	
	type = type.substring(0, 1).toUpperCase() + type.substring(1);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/sh/shCore.js"></script>
<script type="text/javascript" src="js/sh/shBrush<%=type%>.js"></script>
<link type="text/css" rel="stylesheet" href="css/sh/shCoreDefault.css" />
<script type="text/javascript">
	SyntaxHighlighter.all();
</script>

</head>
<body>
	<pre class="brush: <%=brush%>;">
<%
	String encoding=FileUtil.getEncoding(docRoot+file);
	System.out.println(encoding);
	InputStream is = new FileInputStream(docRoot+file);
	byte[] bs = new byte[1024];
	int len = 0;
	String s=null;
	while ((len = is.read(bs)) != -1) {
		if(encoding!=null&&encoding.trim().length()!=0){
			s=new String(bs, 0, len, encoding);
		}else{
			s=new String(bs,0,len);
		}
%>
	<%=s%>
<%
	}
	is.close();
%>
</pre>
</body>
</html>

本文地址

请注意代码中的文件路径,所需的控件为 SyntaxHighlighter
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值