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); /** * View file content directly on the page * @throws FileNotFoundException * @throws UnsupportedEncodingException */ @RequestMapping("look") public String look() throws FileNotFoundException, UnsupportedEncodingException { FIS the FileInputStream = new new the FileInputStream ( "D: \\ Git code \\ \\ \\ TRADE trade_sync the src \\ \\ \\ main Java COM \\ \\ \\ newflows Sync \\ \\ ExecutorConfig.java Executor"); // selected file the InputStreamReader ISR = new new the InputStreamReader (FIS, "UTF-. 8"); // read file the BufferedReader br = new new the BufferedReader (ISR); // read the file into the buffer String line; Tmp String = "<pre style = 'background: #eee; padding: 10px; border-RADIUS: 5px;'>" ; the while ( to true ) // continuously withdrawn row of data in the buffer { the try { IF (((! = br.readLine Line ()) =! null )) { BREAK ; } System.out.println(line); tmp+=line; tmp+="\n"; } catch (IOException e) { e.printStackTrace (); } } tmp+="</pre>"; return tmp; } }
To read files on a web page
Guess you like
Origin www.cnblogs.com/gjq1126-web/p/12193524.html
Recommended
Ranking