我是靠谱客的博主 舒适小鸭子,这篇文章主要介绍在Action中获取文件的路径,读写文件,现在分享给大家,希望可以做个参考。

ActionContext ac = ActionContext.getContext(); 

ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT); 

String x = sc.getRealPath("/");

接着进入项目的工作空间,workspace1bamsbindaglWEB-INFconfig下找到了我们刚刚在eclipse环境中添加的

default.key.

in = new FileInputStream(x+"WEB-INF/config/default.key");

br = new BufferedReader(new InputStreamReader(in));

String code = br.readLine();


2)java项目向某一个文件中写一个字符串

File keyFile = new File("default.key");
if (!keyFile.exists()) {
keyFile.createNewFile();
}
FileWriter fw = new FileWriter(keyFile);
fw.write(finalcode);
fw.close();





最后

以上就是舒适小鸭子最近收集整理的关于在Action中获取文件的路径,读写文件的全部内容,更多相关在Action中获取文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(100)

评论列表共有 0 条评论

立即
投稿
返回
顶部