java.io.ioexception报错怎么办_java.io.IOException: Error writing to server 这个怎么解决

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package com.tz.util;

import java.io.File;

import org.json.JSONArray;

import org.json.JSONObject;

import com.facepp.http.HttpRequests;

import com.facepp.http.PostParameters;

/**

* 人工智能人脸识别的工具类

* @author 城

* @version v1.0

*/

public class FaceMessageUtil {

/**

* 人脸识别工具类

* @param path 需要被识别的图像路径

* @return String 返回的人脸识别后的信息

*/

public static String getFaceMessage(String path){

try {

// 创建http请求

HttpRequests hrs =new HttpRequests("uhqTWEu1sP6mA28de0WkyFAO844739mj","X0zajAlHITVUlP4NpxjIHP-_R_vpaCLs");

PostParameters pps =new PostParameters();

pps.setImg(new File(path));

JSONObject json = hrs.detectionDetect(pps);

// 设置只识别脸部

JSONArray array = json.getJSONArray("face");

//存储人脸信息

StringBuffer buffer =new StringBuffer();

for(int i=0;i

JSONObject jo =array.getJSONObject(i);

JSONObject attrJson =jo.getJSONObject("attribute");

//年龄

JSONObject jsonAge = attrJson.getJSONObject("age");

int range=jsonAge.getInt("range");

int value=jsonAge.getInt("value");

buffer.append("年龄:"+value+"岁");

//性别

String genderStr =attrJson.getJSONObject("gender").getString("value");

Double confidence =attrJson.getJSONObject("gender").getDouble("confidence");

buffer.append("性别:"+genderStr+"(正确率:"+confidence+"%)
");

//种族

String raceStr = attrJson.getJSONObject("race").getString("value");

Double raceConfindence=attrJson.getJSONObject("race").getDouble("confidence");

buffer.append("种族:"+raceStr+"(正确率:"+raceConfindence+"%)
");

//是否在笑

Double smiling =attrJson.getJSONObject("smiling").getDouble("value");

buffer.append("正在笑:"+smiling+"%");

}

return buffer.toString();

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

public static void main (String[] args){

System.out.println("测试人脸识别");

String path="D:\\kankan\\1030.jpg";

String face = getFaceMessage(path);

System.out.println(face);

//1.获取需要被识别的图像,进行人脸识别

//2.通过Face++识别人脸细节

//3.存储在容器中返回到页面中进行展示,同步到数据库中

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 编写程序从文件中读取数据,并输出到控制台。 ```java import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReadFromFile { public static void main(String[] args) { try { File file = new File("data.txt"); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } scanner.close(); } catch (FileNotFoundException e) { System.out.println("File not found."); } } } ``` 2. 编写程序从控制台读取数据,并将数据写入文件。 ```java import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class WriteToFile { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter data: "); String data = scanner.nextLine(); scanner.close(); try { File file = new File("output.txt"); FileWriter writer = new FileWriter(file); writer.write(data); writer.close(); } catch (IOException e) { System.out.println("Error writing to file."); } } } ``` 3. 编写程序从一个文件中复制数据到另一个文件。 ```java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class CopyFile { public static void main(String[] args) { try { File inputFile = new File("input.txt"); File outputFile = new File("output.txt"); FileInputStream inputStream = new FileInputStream(inputFile); FileOutputStream outputStream = new FileOutputStream(outputFile); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); outputStream.close(); } catch (FileNotFoundException e) { System.out.println("File not found."); } catch (IOException e) { System.out.println("Error copying file."); } } } ``` 4. 编写程序读取一个目录下的所有文件,并输出文件名和文件大小。 ```java import java.io.File; public class ListFiles { public static void main(String[] args) { File directory = new File("."); File[] files = directory.listFiles(); for (File file : files) { if (file.isFile()) { System.out.println(file.getName() + " (" + file.length() + " bytes)"); } } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值