zoukankan      html  css  js  c++  java
  • 读文件到网页上

    package com.example.copydemo.controller;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.io.*;
    
    /**
     * @program: copy-demo
     * @description:
     * @author: Gaojq
     * @create: 2020-01-14 16:29
     **/
    
    @RestController
    @RequestMapping("file")
    public class CopyController {
    
        protected static final Logger logger= LoggerFactory.getLogger(CopyController.class);
    
        /**
         * 网页上直接查看文件内容
         * @throws FileNotFoundException
         * @throws UnsupportedEncodingException
         */
        @RequestMapping("look")
        public String look() throws FileNotFoundException, UnsupportedEncodingException {
            FileInputStream fis=new FileInputStream("D:\git\trade\code\trade_sync\src\main\java\com\newflows\sync\executor\ExecutorConfig.java");//选定文件
            InputStreamReader isr=new InputStreamReader(fis,"utf-8");//读入文件
            BufferedReader br=new BufferedReader(isr);//将读入的文件放入缓冲区
            String line;
            String tmp ="<pre style='background: #eee;  padding: 10px; border-radius: 5px;'>";
            while(true)//在缓冲区中不断取出一行数据
            {
                try {
                    if (!((line=br.readLine())!=null)) {
                        break;
                    }
                    System.out.println(line);
                    tmp+=line;
                    tmp+="
    ";
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
            }
            tmp+="</pre>";
            return tmp;
        }
    }

    http://localhost:8080/file/look

  • 相关阅读:
    iOS 自带系统语音识别
    对iOS10新增Api的详细探究
    iOS 技术前瞻
    iOS 之 byte NSString NSData类型转换
    iOS 文本属性
    基本力
    xamarin mac 基础知识 之 界面
    xamarin mac 之 基础知识
    xamarin mac 之 资料
    I方法 thinkphp
  • 原文地址:https://www.cnblogs.com/gjq1126-web/p/12193524.html
Copyright © 2011-2022 走看看