博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring
阅读量:5255 次
发布时间:2019-06-14

本文共 5227 字,大约阅读时间需要 17 分钟。

1 package ese.modify;  2 import java.io.BufferedReader;  3 import java.io.File;  4 import java.io.FileInputStream;  5 import java.io.FileNotFoundException;  6 import java.io.FileOutputStream;  7 import java.io.IOException;  8 import java.io.InputStreamReader;  9 import java.io.OutputStreamWriter; 10  11 import javax.annotation.Resource; 12 import javax.servlet.http.HttpServletRequest; 13 import javax.servlet.http.HttpServletResponse; 14  15 import org.apache.log4j.Logger; 16 import org.springframework.stereotype.Controller; 17 import org.springframework.web.bind.annotation.RequestMapping; 18 import org.springframework.web.bind.annotation.RequestMethod; 19 import org.springframework.web.bind.annotation.RequestParam; 20 import org.springframework.web.bind.annotation.ResponseBody; 21  22 import ese.configure.Configuration; 23 import ese.configure.ConfigurationManager; 24 import ese.controller.BaseController; 25  26 @Controller 27 public class Modifyconf2 extends BaseController{ 28     //private org.codehaus.jackson.map.ObjectMapper jsonMapper = new org.codehaus.jackson.map.ObjectMapper(); 29      30     //@Resource 31     private ConfigurationManager configuremanager; 32      33     @RequestMapping(value="read.do",method=RequestMethod.GET) 34     public @ResponseBody 35     String read(@RequestParam("readpath") String readpath,HttpServletRequest request,HttpServletResponse response) throws IOException{ 36          37         //String url2 = ResourceUtils.findResource(readpath); 38         Configuration conf = configuremanager.getConfiguration(); 39         String path = conf.getProperty("configFilePath"); 40         //String url2 = path + readpath; 41         String url2 =  readpath; 42          43         String content=readtxt2(url2); 44         //content=readtxt2(url2); 45 /*        try { 46             jsonMapper.writeValue(response.getOutputStream(), "success"); 47             } catch (Exception e) { 48             logger.debug("in modifyconf.do jsonMapper.writeValue wrong."); 49         } */ 50      51         return content; 52     } 53      54     @RequestMapping(value="modify.do",method=RequestMethod.GET) 55     public @ResponseBody 56     String modify(@RequestParam("modifypath") String modifypath,@RequestParam("content") String content,HttpServletRequest request,HttpServletResponse response) throws IOException{ 57  58         Configuration conf = configuremanager.getConfiguration(); 59         String path = conf.getProperty("configFilePath"); 60         String url2 = path + modifypath; 61          62         //String url = ResourceUtils.findResource(modifypath); 63         savetxt(url2,content); 64         return "Success"; 65     } 66      67     private void savetxt(String url,String content) { 68         File file=new File(url); 69         OutputStreamWriter outputStreamWriter = null; 70         try { 71             outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file),"UTF-8"); 72         } catch (Exception e) { 73             // TODO Auto-generated catch block 74             e.printStackTrace(); 75         } 76         try { 77             outputStreamWriter.write(content); 78             outputStreamWriter.close(); 79          80         } catch (IOException e) { 81             // TODO Auto-generated catch block 82             e.printStackTrace(); 83         } 84      85     } 86      87     private String readtxt2(String url){ 88         BufferedReader rd = null; 89         try { 90             rd = new BufferedReader(new InputStreamReader(new FileInputStream(url))); 91         } catch (FileNotFoundException e1) { 92             // TODO Auto-generated catch block 93             e1.printStackTrace(); 94         } 95         StringBuffer sb = new StringBuffer(); 96         String line; 97         try { 98             while ((line = rd.readLine()) != null) 99             {100                 sb.append(line);101                 102                 sb.append("\r\n");103                 //sb.append(rd.)104             }105         }catch (Exception e) {106             // TODO Auto-generated catch block107             e.printStackTrace();108         }109         try {110             rd.close();111         } catch (IOException e) {112             // TODO Auto-generated catch block113             e.printStackTrace();114         }115         line= sb.toString();116         return line;117     }118 119     120 121 }
1   2   3     4     
5 修改配置 6
7
8
9
10 11 51 52 53 54 55
56
57
84
85 86
58
80
81 82
83
87 88 89 90 91 92 93 94 181 182

 

转载于:https://www.cnblogs.com/daifei/p/3447874.html

你可能感兴趣的文章
centos下同时启动多个tomcat
查看>>
slab分配器
查看>>
数据清洗
查看>>
【读书笔记】C#高级编程 第三章 对象和类型
查看>>
针对sl的ICSharpCode.SharpZipLib,只保留zip,gzip的流压缩、解压缩功能
查看>>
【转】代码中特殊的注释技术——TODO、FIXME和XXX的用处
查看>>
【SVM】libsvm-python
查看>>
Jmeter接口压力测试,Java.net.BindException: Address already in use: connect
查看>>
Leetcode Balanced Binary Tree
查看>>
Leetcode 92. Reverse Linked List II
查看>>
九.python面向对象(双下方法内置方法)
查看>>
go:channel(未完)
查看>>
[JS]递归对象或数组
查看>>
LeetCode(17) - Letter Combinations of a Phone Number
查看>>
Linux查找命令对比(find、locate、whereis、which、type、grep)
查看>>
路由器外接硬盘做nas可行吗?
查看>>
python:从迭代器,到生成器,再到协程的示例代码
查看>>
Java多线程系列——原子类的实现(CAS算法)
查看>>
在Ubuntu下配置Apache多域名服务器
查看>>
多线程《三》进程与线程的区别
查看>>