List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:Test.java
public static void main(String args[]) throws Exception { ExecutorService pool = new ScheduledThreadPoolExecutor(3); AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("data.txt"), EnumSet.of(StandardOpenOption.READ), pool); CompletionHandler<Integer, ByteBuffer> handler = new CompletionHandler<Integer, ByteBuffer>() { @Override//from ww w . java2 s.c om public synchronized void completed(Integer result, ByteBuffer attachment) { for (int i = 0; i < attachment.limit(); i++) { System.out.println((char) attachment.get(i)); } } @Override public void failed(Throwable e, ByteBuffer attachment) { } }; final int bufferCount = 5; ByteBuffer buffers[] = new ByteBuffer[bufferCount]; for (int i = 0; i < bufferCount; i++) { buffers[i] = ByteBuffer.allocate(10); fileChannel.read(buffers[i], i * 10, buffers[i], handler); } pool.awaitTermination(1, TimeUnit.SECONDS); for (ByteBuffer byteBuffer : buffers) { for (int i = 0; i < byteBuffer.limit(); i++) { System.out.print((char) byteBuffer.get(i)); } } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:"); try {/*from w ww .ja v a2 s . c om*/ FileStore fs = Files.getFileStore(path); printDetails(fs, AclFileAttributeView.class); printDetails(fs, BasicFileAttributeView.class); printDetails(fs, DosFileAttributeView.class); printDetails(fs, FileOwnerAttributeView.class); printDetails(fs, PosixFileAttributeView.class); printDetails(fs, UserDefinedFileAttributeView.class); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:/home/docs/users.txt"); FileStore fileStore = Files.getFileStore(path); System.out.println(//from w w w .j a va 2s .co m "FileAttributeView supported: " + fileStore.supportsFileAttributeView(FileAttributeView.class)); System.out.println("BasicFileAttributeView supported: " + fileStore.supportsFileAttributeView(BasicFileAttributeView.class)); System.out.println("FileOwnerAttributeView supported: " + fileStore.supportsFileAttributeView(FileOwnerAttributeView.class)); System.out.println("AclFileAttributeView supported: " + fileStore.supportsFileAttributeView(AclFileAttributeView.class)); System.out.println("PosixFileAttributeView supported: " + fileStore.supportsFileAttributeView(PosixFileAttributeView.class)); System.out.println("UserDefinedFileAttributeView supported: " + fileStore.supportsFileAttributeView(UserDefinedFileAttributeView.class)); System.out.println("DosFileAttributeView supported: " + fileStore.supportsFileAttributeView(DosFileAttributeView.class)); System.out.println("FileAttributeView supported: " + fileStore.supportsFileAttributeView("file")); System.out.println("BasicFileAttributeView supported: " + fileStore.supportsFileAttributeView("basic")); System.out.println("FileOwnerAttributeView supported: " + fileStore.supportsFileAttributeView("owner")); System.out.println("AclFileAttributeView supported: " + fileStore.supportsFileAttributeView("acl")); System.out.println("PosixFileAttributeView supported: " + fileStore.supportsFileAttributeView("posix")); System.out .println("UserDefinedFileAttributeView supported: " + fileStore.supportsFileAttributeView("user")); System.out.println("DosFileAttributeView supported: " + fileStore.supportsFileAttributeView("dos")); }
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:/home/docs/users.txt"); AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class); List<AclEntry> aclEntryList = view.getAcl(); for (AclEntry entry : aclEntryList) { System.out.println("User Principal Name: " + entry.principal().getName()); System.out.println("ACL Entry Type: " + entry.type()); displayEntryFlags(entry.flags()); displayPermissions(entry.permissions()); System.out.println();/*from w w w . j av a 2 s . com*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("test.txt"); try (AsynchronousFileChannel afc = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { ByteBuffer dataBuffer = getDataBuffer(); Future<Integer> result = afc.write(dataBuffer, 0); while (!result.isDone()) { System.out.println("Sleeping for 2 seconds..."); Thread.sleep(2000);/* w w w. j a v a 2 s. co m*/ } int writtenBytes = result.get(); System.out.format("%s bytes written to %s%n", writtenBytes, path.toAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }
From source file:DeleteDirectory.java
public static void main(String[] args) { try {/* ww w. j av a 2 s . c om*/ Files.walkFileTree(Paths.get("/home"), new DeleteDirectory()); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:TestReadCustData.java
public static void main(String[] args) { AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1"); List<Customer> lCust = new ArrayList<>(); try {/* w ww . j a va 2 s .c o m*/ List<String> s = Files.readAllLines(Paths.get("customer.txt"), Charsets.ISO_8859_1); for (String s1 : s) { if (!s1.startsWith("GRUP")) { Customer c = new Customer(); try { c.setId(Long.parseLong(s1.split("~")[3])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setId(Long.parseLong(s1.split("~")[3])); } try { c.setNama(s1.split("~")[4]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNama(""); } try { c.setShipto(s1.split("~")[9]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setShipto(""); } try { c.setKota(s1.split("~")[12]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKota(""); } try { c.setProvinsi(s1.split("~")[13]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setProvinsi(""); } try { c.setKodePos(s1.split("~")[14]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKodePos(""); } try { c.setNamaArea(s1.split("~")[2]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaArea(""); } try { c.setDKLK(s1.split("~")[15]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setDKLK(""); } try { c.setCreditLimit(Long.parseLong(s1.split("~")[16])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreditLimit(new Long(0)); } try { c.setNpwp(s1.split("~")[11]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNpwp(""); } try { c.setNamaWajibPajak(s1.split("~")[10]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaWajibPajak(""); } try { c.setCreationDate(s1.split("~")[6]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreationDate(""); } try { c.setLastUpdateBy(s1.split("~")[17]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateBy(""); } try { c.setLastUpdateDate(s1.split("~")[18]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateDate(""); } lCust.add(c); } } for (Customer c : lCust) { Customer cc = Ebean.find(Customer.class, c.getId()); if (cc != null) { cc = c; Ebean.update(cc); } System.out.print(c.getId()); System.out.print(" | "); System.out.print(c.getNama()); System.out.print(" | "); System.out.print(c.getShipto()); System.out.print(" | "); System.out.print(c.getNpwp()); System.out.print(" | "); System.out.print(c.getNamaWajibPajak()); System.out.println(); } } catch (IOException ex) { Logger.getLogger(TestReadCustData.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.dal33t.powerfolder.util.AddLicenseHeader.java
/** * @param args */ public static void main(String[] args) { addLicInfoToDir(Paths.get(".")); }
From source file:com.textocat.textokit.postagger.opennlp.PackageModelZipAsArtifact.java
public static void main(String[] args) throws IOException { PackageModelZipAsArtifact cli = new PackageModelZipAsArtifact(); new JCommander(cli, args); Path inputZipPath = Paths.get(cli.inputZipPathStr); if (!Files.isRegularFile(inputZipPath)) { System.err.println(inputZipPath + " is not an existing file."); System.exit(1);/*from w ww . j a v a2 s . com*/ } POSModelJarManifestBean manifestBean = new POSModelJarManifestBean(cli.languageCode, cli.modelVariant); Path outputJarPath = inputZipPath .resolveSibling(FilenameUtils.getBaseName(inputZipPath.getFileName().toString()) + ".jar"); try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputJarPath))) { JarOutputStream jout = new JarOutputStream(out, manifestBean.toManifest()); jout.putNextEntry(new ZipEntry(ClasspathPOSModelHolder.getClassPath(manifestBean.getLanguageCode(), manifestBean.getModelVariant()))); FileUtils.copyFile(inputZipPath.toFile(), jout); jout.closeEntry(); jout.close(); } }
From source file:com.github.ivkustoff.app.Application.java
public static void main(String[] args) { if (args != null && args.length > 0) { Path testRoot = Paths.get(args[0]); if (testRoot.toFile().exists()) { System.out.println("Parsing data..."); DirCrawler crawler = new DirCrawler(testRoot).crawl(); System.out.println(crawler.errors()); List<ParsedTopicData> parsedTopicData = crawler.topics(); List<Topic> realTopics = new ArrayList<>(); for (ParsedTopicData topicData : parsedTopicData) { realTopics.add(new RealTopic(topicData).generateTopic()); }//w ww . ja v a2 s . c om System.out.println("Starting server..."); ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args); applicationContext.getBean(TopicRepository.class).addTopics(realTopics); } } else { System.out.println("Please provide topicRoot directory as program argument"); } }