??? /**
??? ?* 把字符串写到文件中
??? ?*/
??? public static? void write2File(String str,String fileName){
??? ???
??? ??? File file = null;
??? ??? OutputStreamWriter osWriter = null;
??? ??? BufferedWriter bufferWriter = null;
??? ???
??? ??? try {
??? ??? ??? file = new File(fileName);
??? ??? ??? if(!file.exists()){
??? ??? ??? ??? file.createNewFile();
??? ??? ??? }
??? ??? ??? osWriter = new OutputStreamWriter(new FileOutputStream(file,true),"UTF-8");
??? ??? ??? bufferWriter = new BufferedWriter(osWriter);
??? ??? ??? bufferWriter.write(str);
??? ??? ??? bufferWriter.close();
??? ??? } catch (Exception e) {
??? ??? ??? System.err.println("Error: 写入文件出错。。。");
??? ??? ??? e.printStackTrace();
??? ??? }
??? }
??? /**
??? ?* 从文件中读取字符串
??? ?*/
??? public static String readFromFile(String filePath){
??? ???
??? ??? String fileContent = null;
??? ??? File file = null;
??? ??? InputStreamReader streamReader = null;
??? ??? BufferedReader bufferReader = null;
??? ???
??? ??? String line = null;
??? ???
??? ??? file = new File(filePath);
??? ??? if(file.isFile() && file.exists()){
??? ??? ???
??? ??? ??? try {
??? ??? ??? ??? streamReader = new InputStreamReader(new FileInputStream(file),"UTF-8");
??? ??? ??? ??? bufferReader = new BufferedReader(streamReader);
??? ??? ??? ???
??? ??? ??? ??? while((line = bufferReader.readLine()) != null){
??? ??? ??? ??? ??? fileContent += line;
??? ??? ??? ??? }
??? ??? ??? ??? streamReader.close();
??? ??? ??? } catch (Exception e) {
??? ??? ??? ??? System.err.println("Error:从文件中读取字符串时候出错");
??? ??? ??? ??? e.printStackTrace();
??? ??? ??? }
??? ??? }
??? ??? return fileContent;
??? }