转换为try-with-resources警告

时间:2014-12-06 22:58:05

标签: java eclipse netbeans warnings

警告"转换为try-with-resources" ,警告出现在此代码中的(outStream)指令下,请帮忙吗?

 static void doTestByteFiles() throws IOException {

   File file = new File("sample1.data");
   FileOutputStream outStream = new FileOutputStream(file); //Warning!!!!

   byte[] outByteArray = {10,20,30,40,50,60,70,80,(byte)'J',(byte)'a',(byte)'v',(byte)'a'};


   outStream.write(outByteArray);
   outStream.close();

   FileInputStream inStream = new  FileInputStream(file);

   int fileSize = (int) file.length();
   byte[] inByteArray = new byte[fileSize];
   inStream.read(inByteArray);

   for (int i = 0; i < fileSize; i++) {
     System.out.println((char) inByteArray[i]);
   }

inStream.close();
 }

0 个答案:

没有答案