Here you can find the source of createFileFromText(String sourceText, IPath path)
Parameter | Description |
---|---|
sourceText | the file's contents |
path | the absolute path of the file to create |
Parameter | Description |
---|---|
IOException | if creating the file fails |
public static void createFileFromText(String sourceText, IPath path) throws IOException
//package com.java2s; /******************************************************************************* * Copyright 2014 Google Inc. All Rights Reserved. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * 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./* ww w .j av a2s . c o m*/ *******************************************************************************/ import com.google.common.base.Preconditions; import org.eclipse.core.runtime.IPath; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; public class Main { /** * Creates a file from input string text. * * @param sourceText the file's contents * @param path the absolute path of the file to create * @throws IOException if creating the file fails */ public static void createFileFromText(String sourceText, IPath path) throws IOException { Preconditions.checkArgument(path.isAbsolute()); Path file = FileSystems.getDefault().getPath(path.toOSString()); Files.write(file, sourceText.getBytes()); } }