Here you can find the source of appendLineToFile(String fileName, String format, Object... vals)
Parameter | Description |
---|---|
fileName | Name of a file to append to. |
format | A line format. |
vals | A line format args. |
Parameter | Description |
---|---|
IOException | If IO error occurs. |
public static void appendLineToFile(String fileName, String format, Object... vals) throws IOException
//package com.java2s; /* //w w w. j a v a 2s . c om Copyright (C) GridGain Systems. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.io.*; public class Main { /** * Appends a line to a file. Creates parent directories if any of those do not * exist. * * @param fileName Name of a file to append to. * @param format A line format. * @param vals A line format args. * @throws IOException If IO error occurs. */ public static void appendLineToFile(String fileName, String format, Object... vals) throws IOException { new File(fileName).getParentFile().mkdirs(); try (Writer out = new BufferedWriter(new FileWriter(fileName, true))) { out.write(String.format(format + '\n', vals)); } } }