Java 中文件的操作
@Testpublic void testWriteContentWithFileNameAndInputStream() throws IOException{String fileName;//创建一个一文件,封装成一个InputStreamString fileP = "creatDirectoryTest//input.txt";File f = new File(fileP);if(!f.exists()){f.getParentFile().mkdirs();f.createNewFile();}if(f.exists()){ String str = "alksdjfaslkdfja;lsdkjf;askdfj;askdfj;askdjfaskdjfjian加加大妇女家阿道夫将加速的那个静安寺地方静安寺地方静安寺地方"; BufferedWriter bwrite = new BufferedWriter(new FileWriter(fileP,true)); bwrite.write(str); bwrite.flush(); bwrite.close(); }try {InputStream inStream=new FileInputStream("creatDirectoryTest//input.txt");fileName = "creatDirectoryTest//writeContent.txt";FileUtil.writeContent(fileName, inStream);File contentFile = new File(fileName);InputStream inputstream = new FileInputStream(contentFile);int size = inputstream.available();Assert.assertEquals(true, size>0);} catch (FileNotFoundException e) {e.printStackTrace();} f.delete();}