zoukankan      html  css  js  c++  java
  • 使用java 程序创建格式为utf-8文件的方法(写入和读取json文件)

    使用java 程序创建格式为utf-8文件的方法:
      
    try{
                File file=new   File("C:/11.jsp");  
                OutputStream out=new FileOutputStream(file);
                BufferedWriter   rd   =   new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
                rd.write("333333333333中国");
                rd.close();
                out.close();
            }catch(IOException e){
                e.printStackTrace();
            }

    //判断文件是否存在

    //(获取服务器的config下的路径)
    File fileExit = new File(this.getClass().getClassLoader().getResource(path).toURI().getPath());
    if(!fileExit.exists()){
    return fileContent;
    }

    //(获取webroot下文件路径)

    ServletContext sctx = ServletActionContext.getServletContext();
    String path = sctx.getRealPath("/");// 服务器文件路径
    File filePath=new File("uploadfiles/temp/"+"2016-11-09");//拼接文件路径



    String fileContent = "";
    InputStreamReader file = new InputStreamReader(
    IGetEshopid.class.getClassLoader()
    .getResourceAsStream(path), "UTF-8");
    BufferedReader reader = new BufferedReader(file);

    String tempString = null;
    while ((tempString = reader.readLine()) != null) {
    fileContent += tempString;
    }
    reader.close();
    return fileContent;

  • 相关阅读:
    C#串口通信程序SerialPort类
    51单片机和PC串口异步通信
    Robotics ToolBox机械臂仿真
    51单片机和PC串口异步通信(续)
    谈谈FFT有何用
    volatile关键字的使用
    如何走好后面的路
    51单片机液晶显示计时器
    IDE86汇编语言环境使用
    不使用跳转的宏CV_IMIN分析
  • 原文地址:https://www.cnblogs.com/runerering/p/6053245.html
Copyright © 2011-2022 走看看