栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java不兼容魔术值4022320623

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java不兼容魔术值4022320623

好吧,感谢@Asaph提到下载出错了,我想通了。

基本上下载很好,这就是我编写文件的方式。

我在下载项目时,我正在下载源代码和二进制文件,但是我正在写两个文件,就好像它们是一样的。

因此,更改了代码以检查文件类型,然后在必要时使用适当的编写器。如果有人奇迹般地遇到了相同的问题或正在做类似的事情,则代码如下:

(请注意,这是5秒钟前写的,用于解决该问题,并且写得很差,我自己打算对其进行重构,但是我不能为您做所有事情)

public void download(String project, String version, String location){    for(S3ObjectSummary s: getObjectList())    {        String[] data = s.getKey().split("/");        if(data[0].equals(project) && data[1].equals(version))        { S3Object object = s3.getObject(s3BucketName,s.getKey()); InputStream input = object.getObjectContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); File file = new File(location +"/"+ data[0] + "/" + data[2] + "/" + data[3] + "/" + data[4]); if(!file.exists()) {       try {file.getParentFile().mkdirs();  file.createNewFile();     } catch (IOException e) {         e.printStackTrace();     } } try  {     if(data[4].endsWith(".java"))     {     Writer writer = new OutputStreamWriter(new FileOutputStream(file));     while (true) {         String line = reader.readLine();          if (line == null)    break;          writer.write(line + "n");     }     writer.close();     }     else if(data[4].endsWith(".class"))     {         System.out.println("Writing Classes");         byte[] buffer = new byte[8 * 1024];         try {    OutputStream output = new FileOutputStream(file.getAbsolutePath());    try {      int bytesRead;      while ((bytesRead = input.read(buffer)) != -1) {        output.write(buffer, 0, bytesRead);      }    } finally {      output.close();    }  } finally {    input.close();  }     } } catch (FileNotFoundException e) {     e.printStackTrace(); } catch (IOException e) {     // TODO Auto-generated catch block     e.printStackTrace(); }        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/507941.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号