package transfor;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class demo { private static ArrayList<String> filelist = new ArrayList<String>();
private static String CHARSET = "utf-8"; public static void main(String[] args) throws IOException {
refreshFileList("F:\\11");
for(int i = 0; i<filelist.size();i++) {
long a = System.currentTimeMillis();
System.out.println(filelist.get(i));
String text =""; String wstr = filelist.get(i).replace(".json", "")+".txt"; text = run(filelist.get(i)); putconent(text,wstr); long b = System.currentTimeMillis(); System.out.println("程序运行时间: "+(b-a)+"ms");
}
filelist.clear();
} public static void refreshFileList(String strPath) {
File dir = new File(strPath);
File[] files = dir.listFiles(); if (files == null)
return;
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
refreshFileList(files[i].getAbsolutePath());
} else {
String strFileName = files[i].getAbsolutePath().toLowerCase();
filelist.add(files[i].getAbsolutePath());
}
}
} private static void putconent(String content, String filename) {
try {
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(filename)
)
);
bw.write(content);
bw.flush();
bw.close(); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} } public static String getContent(String filename)throws Exception {
String ss = "";
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(filename), "utf-8"));
String line="";
while ((line = br.readLine()) != null) {
ss += line;
}
br.close(); return ss;
} public static String run(String filename) {
String rtn = "";
try { URL url = new URL("http://172.19.34.128:8801/charCorrect"); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");//POST
connection.setDoInput(true);
connection.setDoOutput(true);
// connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
// connection.setRequestProperty("content-type", "test/xml");
connection.setRequestProperty("content-type", "application/json"); connection.connect(); String con = getContent(filename); StringBuffer requestXml = new StringBuffer();
requestXml.append(con); PrintWriter writer = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), CHARSET));
try {
writer.print(requestXml.toString());
writer.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
writer.close();
} if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("Error: " + connection.getResponseMessage());
}
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), CHARSET));
StringBuffer rtnBuffer = new StringBuffer();
try {
String temp = reader.readLine();
while (temp != null) {
rtnBuffer.append(temp);
temp = reader.readLine();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
reader.close();
} rtn = rtnBuffer.toString(); } catch (Exception e) {
rtn = "失败";
}
try { System.out.println("结果:"+rtn); } catch (Exception e) {
e.printStackTrace();
}
return rtn;
}
}

读文件/写文件。http请求。读取文件列表。的更多相关文章

  1. ASP.NET最误导人的错误提示:“未预编译文件,因此不能请求该文件”

    昨天在一个ASP.NET MVC项目中,一个预编译后的视图访问时总是报错: 未预编译文件,因此不能请求该文件(The file has not been pre-compiled, and canno ...

  2. 文件结束符和C\C++读取文件方式

    http://www.cnblogs.com/cvbnm/articles/2003056.html 约定编译器为 gcc2/x86: 所以 char, unsigned char 为 8 位, in ...

  3. JAVA 解决 SpringBoot 本地读取文件成功,打包后读取文件失败的方法

    SpringBoot 的日常开发中,我们会发现当我们使用  InputStream input = getClass.getResource(path) 读取文件或者模板时,在 ida 中运行 测试的 ...

  4. day08文件操作的三步骤,基础的读,基础的写,with...open语法,文件的操作模式,文件的操作编码问题,文件的复制,游标操作

    复习 ''' 类型转换 1.数字类型:int() | bool() | float() 2.str与int:int('10') | int('-10') | int('0') | float('-.5 ...

  5. python文件处理-读、写

    Python中文件处理的操作包括读.写.修改,今天我们一起来先学习下读和写操作. 一.文件的读操作 例一: #文件读操作 f = open(file="first_blog.txt" ...

  6. File IO(NIO.2):读、写并创建文件

    简介 本页讨论读,写,创建和打开文件的细节.有各种各样的文件I / O方法可供选择.为了帮助理解API,下图以复杂性排列文件I / O方法 在图的最左侧是实用程序方法readAllBytes,read ...

  7. 读、写SD上的文件请按如下步骤进行

    1.调用Environment的getExternalStorageState()方法判断手机上是否插入了SD卡,并且应用程序具有读写SD卡的权限.例如使用如下代码//Environment.getE ...

  8. 如何有效的使用C#读取文件

    如何有效的使用C#读取文件  你平时是怎么读取文件的?使用流读取.是的没错,C#给我们提供了非常强大的类库(又一次吹捧了.NET一番),里面封装了几乎所有我们可以想到的和我们没有想到的类,流是读取文件 ...

  9. PHP —— 读取文件到二维数组

    转自:PHP读取自定义ini文件到二维数组 读取文件,可以使用file_get_contents,file,parse_ini_file等,现在有一个需求,需要读取如下格式的文件: [food] ap ...

  10. java读取文件多种方法

    1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile {     /**      * 以字节为单位读取文件,常用 ...

随机推荐

  1. SpringCloud实践引入注册中心+配置中心

    随着服务数量的增多,尤其是多数项目涉及jni本地方法的调用,所需参数配置较多,同时内存溢出等维护问题时常发生.鉴于此,原tomcat集群的使用已难满足需求,而微服务的思想契合当前项目实践,特在服务端构 ...

  2. mpvue——小程序修改input的placehold样式

    前言 官方地址 https://developers.weixin.qq.com/miniprogram/dev/component/input.html 用placeholder-class的时候没 ...

  3. Word自定义多级列表样式

    Word自定义多级列表样式: 1. 2. 3.取个名字 在这里鼠标移上时显示 : 4. 5. 定义完成,即可使用:

  4. 用Pytorch训练线性回归模型

    假定我们要拟合的线性方程是:\(y=2x+1\) \(x\):[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] \(y\):[1, 3, 5, 7, ...

  5. <Android基础> (四) Fragment Part 2

    4.3 Fragment的生命周期 4.3.1 Fragment的状态和回调 1.运行状态 当一个Fragment是可见的,并且它关联的活动正处于运行状态是,该Fragment也处于运行状态 2.暂停 ...

  6. shell 基础(二)变量

    1. shell变量的定义 1)Shell 支持以下三种定义变量的方式: variable=value variable='value' variable="value" 特点 1 ...

  7. c#操作IIS之IISHelper

    //----------------------------------------------------------------------- // <copyright file=&quo ...

  8. Linux下查看Nginx安装目录、版本号信息及当前运行的配置文件

    Linux环境下,怎么确定Nginx的安装路径 输入命令行: ps -ef | grep nginx 摁回车,将出现如下图片: master process 后面的就是的 /data/software ...

  9. Day049--jQuery的文档操作和事件介绍

    今日内容 DOM操作(CRUD) js中DOM document.createElement('p') appendChild() insertBefore() removeChild() 创建元素 ...

  10. SpringBoot系列: SpringBoot Web项目中使用Shiro 之二

    ==================================Shiro 的加深理解:==================================1. Shiro 和 Spring 系组 ...