644f79e225b5356daf91fc205fa4f494b3196401
[nemo.git] / nemo-tools / sandbox / src / main / java / org / opendaylight / nemo / tool / sandbox / utils / FileUtils.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.nemo.tool.sandbox.utils;
10
11 import java.io.*;
12
13 /**
14  * Created by hj on 12/11/15.
15  */
16 public class FileUtils {
17     private static Logger log = LoggerFactory.getLogger(FileUtils.class);
18     public static void write(String path, String content) {
19         try {
20             File f = new File(path);
21             if (!f.exists()) {
22                 if (!f.createNewFile()) {
23                     System.out.println("Can not create new file " + path);
24                 }
25             }
26             BufferedWriter output = new BufferedWriter(new FileWriter(f));
27             output.write(content);
28             output.close();
29         } catch (Exception e) {
30             log.error(e);
31         }
32     }
33 }