首页 新闻 会员 周边

怎么获得文件的换行信息

0
[已解决问题] 解决于 2016-04-13 10:53

我在磁盘上有个.txt文件,数据库blog中存取的是在磁盘上的当前.txt文件的路径,我通过这个输入流获取了文件内容,输出到网站页面上,文件上的换行信息都没有了,我怎么能让文件原样输出在web页面呢????

还有我要实现后台管理博文,怎么实现博客园这种写博文的效果呢,加粗之类的操作???

public class BlogToWebPage {
    public static String showBlog(String path) throws IOException{
        File file=new File(path);
        if(!file.exists())
            return "博文不存在!!!";
        BufferedInputStream in=new BufferedInputStream(new FileInputStream(file));
        /*StringBuilder s=new StringBuilder("");*/
        String s="";
        int data=0;
        byte buffer[]=new byte[4096];
        while((data=in.read(buffer))!=-1){s+=new String(buffer,0,data);}
        return s;
    }
}
不被女生喜欢好多年的主页 不被女生喜欢好多年 | 初学一级 | 园豆:39
提问于:2016-04-12 19:33
< >
分享
最佳答案
0
public class BlogToWebPage {

        public static void main(String args[]) throws IOException {
            File file=new File("G:\\1.txt");
            InputStream is=new FileInputStream(file);
            BufferedReader in=new BufferedReader(new InputStreamReader(is,"utf-8"));
           // BufferedInputStream in=new BufferedInputStream(new FileInputStream(file));
            String s="";
            String  data="";
            while((data=in.readLine())!=null){
                for(String obj:data.split("\n")){
                    System.out.println(obj);
                }
            }

        }

}

 

不被女生喜欢好多年 | 初学一级 |园豆:39 | 2016-04-12 22:12

\r\n -> <br/>

吴瑞祥 | 园豆:29449 (高人七级) | 2016-04-13 08:37

@吴瑞祥: 是的

不被女生喜欢好多年 | 园豆:39 (初学一级) | 2016-04-13 10:52
其他回答(1)
0

存html不就行了

上帝之城 | 园豆:2549 (老鸟四级) | 2016-04-12 20:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册