List of usage examples for java.io File delete
public boolean delete()
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/Demo.txt"); System.out.println(file.delete()); }
From source file:Main.java
public static void main(String[] args) { File file = new File("yourFile.txt"); System.out.println(file.delete()); }
From source file:FileIOApp.java
public static void main(String args[]) throws IOException { FileOutputStream outStream = new FileOutputStream("test.txt"); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));//from w w w .java 2 s. c o m outStream.close(); FileInputStream inStream = new FileInputStream("test.txt"); int inBytes = inStream.available(); System.out.println("inStream has " + inBytes + " available bytes"); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf, 0, inBytes); System.out.println(bytesRead + " bytes were read"); System.out.println("They are: " + new String(inBuf)); inStream.close(); File f = new File("test.txt"); f.delete(); }
From source file:MainClass.java
public static void main(String[] a) { File file = new File("c:\\test\\test.txt"); boolean success = file.delete(); System.out.println(success);//from ww w . j a va 2s. c om }
From source file:FileAttributesDemo.java
public static void main(String[] args) throws IOException { // Create a new file, by default canWrite=true, readonly=false File file = new File("test.txt"); if (file.exists()) { file.delete(); }//from w w w . java 2 s. com file.createNewFile(); System.out.println("Before. canWrite?" + file.canWrite()); // set to read-only, atau canWrite = false */ file.setWritable(false); System.out.println("After. canWrite?" + file.canWrite()); }
From source file:edu.nju.cs.inform.jgit.CreateNewRepository.java
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); localPath.delete(); // create the directory try (Git git = Git.init().setDirectory(localPath).call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); }/*from w w w .j a v a 2s .c om*/ FileUtils.deleteDirectory(localPath); }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("test.txt"); // tries to delete a non-existing file boolean bool = f.delete(); System.out.println("File deleted: " + bool); }
From source file:Delete.java
public static void main(String[] argv) throws IOException { // Construct a File object for the backup created by editing // this source file. The file probably already exists. // My editor creates backups by putting ~ at the end of the name. File bkup = new File("Delete.java~"); // Quick, now, delete it immediately: bkup.delete(); }
From source file:com.dopsun.msg4j.tools.CodeGen.java
/** * @param args/*from ww w . jav a 2 s. c om*/ * @throws IOException * @throws MalformedURLException * @throws ParseException */ public static void main(String[] args) throws MalformedURLException, IOException, ParseException { Options options = new Options(); options.addOption("o", "out", true, "Output file"); options.addOption("s", "src", true, "Source file"); options.addOption("l", "lang", true, "Language"); CommandLineParser cmdParser = new DefaultParser(); CommandLine cmd = cmdParser.parse(options, args); String lang = cmd.getOptionValue("lang", "Java"); String srcFile = cmd.getOptionValue("src"); String outFile = cmd.getOptionValue("out"); YamlModelSource modelSource = YamlModelSource.load(new File(srcFile).toURI().toURL()); YamlModelParser parser = YamlModelParser.create(); ModelInfo modelInfo = parser.parse(modelSource); String codeText = null; if (lang.equals("Java")) { codeText = Generator.JAVA.generate(modelInfo); } else { throw new UnsupportedOperationException("Unrecognized lang: " + lang); } if (outFile != null) { File file = new File(outFile); if (file.exists()) { file.delete(); } file.createNewFile(); Files.append(codeText, new File(outFile), Charsets.UTF_8); } else { System.out.println(codeText); } }
From source file:edu.cuhk.hccl.TripRealRatingsApp.java
public static void main(String[] args) throws IOException { File dir = new File(args[0]); File outFile = new File(args[1]); outFile.delete(); StringBuilder buffer = new StringBuilder(); for (File file : dir.listFiles()) { List<String> lines = FileUtils.readLines(file, "UTF-8"); String hotelID = file.getName().split("_")[1]; String author = null;// w w w . j ava 2s.com boolean noContent = false; for (String line : lines) { if (line.startsWith("<Author>")) { try { author = line.split(">")[1].trim(); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("[ERROR] An error occured on this line:"); System.out.println(line); continue; } } else if (line.startsWith("<Content>")) { // ignore records if they have no content String content = line.split(">")[1].trim(); if (content == null || content.equals("")) noContent = true; } else if (line.startsWith("<Rating>")) { String[] rates = line.split(">")[1].trim().split("\t"); if (noContent || rates.length != 8) continue; // Change missing rating from -1 to 0 for (int i = 0; i < rates.length; i++) { if (rates[i].equals("-1")) rates[i] = "0"; } buffer.append(author + "\t"); buffer.append(hotelID + "\t"); // overall buffer.append(rates[0] + "\t"); // location buffer.append(rates[3] + "\t"); // room buffer.append(rates[2] + "\t"); // service buffer.append(rates[6] + "\t"); // value buffer.append(rates[1] + "\t"); // cleanliness buffer.append(rates[4] + "\t"); buffer.append("\n"); } } // Write once for each file FileUtils.writeStringToFile(outFile, buffer.toString(), true); // Clear buffer buffer.setLength(0); System.out.printf("[INFO] Finished processing %s\n", file.getName()); } System.out.println("[INFO] All processinig are finished!"); }