public static void main(String[] args) { for (File f : new File("C:\\Users\\wendal\\workspace\\git\\github\\nutzmore").listFiles()) { if (!f.getName().startsWith("nutz-")) continue; // System.out.println(f); File readme = new File(f, "README.md"); if (!readme.exists()) { System.out.println("miss README.md " + f); StringBuilder sb = new StringBuilder(); sb.append("" + f.getName()).append("\r\n"); sb.append("==================================\r\n\r\n"); sb.append("简介(可用性:开发中)\r\n"); sb.append("==================================\r\n\r\n"); sb.append("待编写"); Files.write(readme, sb); } boolean flag = true; List<String> lines = Files.readLines(readme); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (line.startsWith("简介(可用性:")) { String avi = line.substring("简介(可用性:".length(), line.length() - 1); if (avi.equals("生产")) avi = "**" + avi + "**"; // System.out.println(lines.get(i+3)); String shortt = lines.get(i + 3); String maven = "![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.nutz/" + f.getName() + "/badge.svg)"; String link = "[" + f.getName() + "](https://github.com/nutzam/nutzmore/tree/master/" + f.getName() + ")"; System.out.printf("| %s | %s | %s | %s |\r\n", link, maven, shortt, avi); flag = false; break; } } if (flag) { StringBuilder sb = new StringBuilder(); sb.append("简介(可用性:开发中)\r\n"); sb.append("==================================\r\n\r\n"); sb.append("待编写"); lines.add(3, sb.toString()); Files.write(readme, Strings.join("\r\n", lines.toArray())); } } }
// for issue 278 @Test public void test_clob() throws IOException, SQLException { dao.create(BinObject.class, true); BinObject bin = new BinObject(); File f = File.createTempFile("clob", "data"); Files.write(f, "中文"); bin.setMyClob(new SimpleClob(f)); dao.insert(bin); bin = dao.fetch(BinObject.class); String str = Lang.readAll(bin.getMyClob().getCharacterStream()); assertEquals("中文", str); }
public NutMap upload(TempFile tmp, int userId) throws IOException { NutMap re = new NutMap(); if (userId < 1) return re.setv("msg", "请先登陆!"); if (tmp == null || tmp.getSize() == 0) { return re.setv("msg", "空文件"); } if (tmp.getSize() > 10 * 1024 * 1024) { tmp.delete(); return re.setv("msg", "文件太大了"); } String id = R.UU32(); String path = "/" + id.substring(0, 2) + "/" + id.substring(2); File f = new File(imageDir + path); Files.createNewFile(f); Files.write(f, tmp.getInputStream()); tmp.delete(); re.put("url", Mvcs.getServletContext().getContextPath() + "/yvr/upload" + path); re.setv("success", true); return re; }
public static void main(String[] args) { String path = Take.class.getResource("/").getPath(); String proFile = path + "file.json"; final List<String> urls = new ArrayList<String>(); Files.readLine( Files.findFile(proFile), new Callback<String>() { @Override public void invoke(String str) { urls.add(str); } }); for (String url : urls) { if (StringUtils.isBlank(url)) { continue; } Response req = Http.get(url); String savePath = path + "/temp/" + StringUtils.substringAfterLast(url, "/"); savePath = StringUtils.substringBefore(savePath, "?"); Files.write(savePath, req.getStream()); System.out.println("save Path:" + savePath); } }
public void truncate(long len) throws SQLException { Files.write(file, new Byte[] {}); }