MCPcopy Create free account
hub / github.com/ChenSen5/api_autotest / writeFile

Method writeFile

src/main/java/com/sen/api/utils/FileUtil.java:135–172  ·  view source on GitHub ↗
(InputStream is, String filePath)

Source from the content-addressed store, hash-verified

133 }
134
135 public static boolean writeFile(InputStream is, String filePath) {
136 File file = new File(filePath);
137 if (!file.getParentFile().exists()) {
138 file.getParentFile().mkdirs();
139 }
140 FileOutputStream fileout;
141 try {
142 fileout = new FileOutputStream(file);
143 } catch (FileNotFoundException e) {
144 // TODO Auto-generated catch block
145 e.printStackTrace();
146 return false;
147 }
148 /**
149 * 根据实际运行效果 设置缓冲区大小
150 */
151 byte[] buffer = new byte[10 * 1024];
152 int ch = 0;
153 try {
154 while ((ch = is.read(buffer)) != -1) {
155 fileout.write(buffer, 0, ch);
156 }
157 return true;
158 } catch (IOException e) {
159 // TODO Auto-generated catch block
160 e.printStackTrace();
161 return false;
162 } finally {
163 try {
164 is.close();
165 fileout.flush();
166 fileout.close();
167 } catch (IOException e) {
168 // TODO Auto-generated catch block
169 e.printStackTrace();
170 }
171 }
172 }
173}

Callers 1

apiTestMethod · 0.95

Calls

no outgoing calls

Tested by 1

apiTestMethod · 0.76