Java写本地文件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.io.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<% 
	String userName = request.getParameter("user");
	String userPwd = request.getParameter("pwd");
	String txtName = "abc.txt";
	File f = new File("F:/abc/abc/");
	File file = new File("F:/abc/abc/"+txtName);
	if(!f.exists())f.mkdirs();
	if(!file.exists()) {
		try {
			file.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	BufferedWriter bw;
	try {
		bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
		bw.append(userName+"\t"+userPwd);
		bw.newLine();
		bw.flush();
		bw.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	BufferedReader br;
	try {
		br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
		while(br.read() != -1) {
			System.out.println(br.readLine());
		}
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
%>
修改文件属性
http://blog.csdn.net/zyb134506/article/details/4790072

你可能感兴趣的:(java)