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. Spring MVC 使用介绍(六)—— 注解式控制器(二):请求映射与参数绑定

    一.概述 注解式控制器支持: 请求的映射和限定 参数的自动绑定 参数的注解绑定 二.请求的映射和限定 http请求信息包含六部分信息: ①请求方法: ②URL: ③协议及版本: ④请求头信息(包括Co ...

  2. SpringCloud 过滤器

    在网关中配置过滤器 验证签名 package com.kps.zuul.filter; import com.kps.common.BodyReaderHttpServletRequestWrappe ...

  3. Git冲突:You have not concluded your merge

    You have not concluded your merge. (MERGE_HEAD exists) Git本地有修改如何强制更新 我尝试过用git pull -f,总是提示 You have ...

  4. java extends和implements区别

    一.作用说明 extends 是继承某个类, 继承之后可以使用父类的方法, 也可以重写父类的方法; implements 是实现多个接口, 接口的方法一般为空的, 必须重写才能使用 二.补充 JAVA ...

  5. [hashcat]基于字典和暴力破解尝试找到rar3-hp的压缩包密码

    1.使用rar2john找到md5 2.基于字典 hashcat -a 0 -m 12500 /root/Desktop/md5.txt /usr/share/wordlists/weakpass.t ...

  6. LoadRunner【第五篇】关联

    关联的定义及使用场景 关联:将服务器提供动态变化的值存放在变量中,当需要使用该变量时,由LoadRunner自动从服务器响应的信息中获取该值,并在后面使用的过程中进行替换.(也可能是前端页面动态生成的 ...

  7. C-static,auto,register,volatile

    static 一:静态,意思就是呆在一个地方,不想动,大概就是编译期间就确定地址了.首先了解下C中的进程内存布局: 1)正文段(.text)——CPU执行的机器指令部分:一个程序只有一个副本:只读,防 ...

  8. 使用catboost解决ML中高维度不平衡数据集挑战的解决方案

    python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...

  9. Entity Framework入门教程(12)--- EF进行批量添加/删除

    EF6添加了批量添加/删除实体集合的方法,我们可以使用DbSet.AddRange()方法将实体集合添加到上下文,同时实体集合中的每一个实体的状态都标记为Added,在执行SaveChange()方法 ...

  10. 《Java》第三周学习总结 20175301

    Java第三周学习总结 首先视频学习了第四章的内容,第四章整体内容较多较复杂,但是整体脉络清晰理解起来很容易,学习 类,方法,对象,组合与复用,实例成员与类成员,包,访问权限,类封装,对象数组等内容 ...