java添加文字水印插件_java之io添加文字水印
實現(xiàn)統(tǒng)計個人某個目錄下的java 文件個數(shù),總代碼行數(shù)。
package j09;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Tongh {
public static void main(String[] args) throws IOException {
String str = "E:/java/";
tongji(str);
System.out.printf("java文件%d共%d行代碼",a,d);
}
public static void tongji(String str) {
try {
tongji(new File(str));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static int a = 0, s = 0, d = 0;
public static void tongji(File file) throws IOException {
if (file.isDirectory()) {
File[] ile = file.listFiles();
for (File il : ile) {
tongji(il);
}
} else {
String name = file.getName();String kuo="";
if(name.lastIndexOf(".")==-1) {}else {
kuo =name.substring(name.lastIndexOf("."));}
if (kuo. contains(".java")) {
++a;
FileReader read = new FileReader(file);
BufferedReader fil = new BufferedReader(read);
s=0;
while (fil.ready()) {
fil.readLine();
++s;
}
d += s;
System.out.println(file.getName()+s+"行");
}
}
}
}
自動加水印
package j09;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Tu {
public static void main(String[] args) {
try {
shui();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static void shui() throws IOException {
String str="C:\\Users\\Administrator\\Pictures\\error.png";
File file=new File(str);
shui(file);
}
public static void shui(File file) throws IOException {
String dst=file.getPath();
BufferedImage s=ImageIO.read(file);
int width =s.getWidth();
int height= s.getHeight();
BufferedImage i=new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
Graphics g=i.getGraphics();
g.drawImage(s, 0, 0, width,height,null);
g.setColor(new Color(0,0,122,50));
g.fillRect(0, 0, width, height);
g.setColor(new Color(255,32,122,120));
g.setFont(new Font("黑體",Font.BOLD,40));
int x=width-200;
int y=height-35;
g.drawString("你好哈", x, y);
g.dispose();
ImageIO.write(i, "jpg", new File(dst));
}
}
總結(jié)
以上是生活随笔為你收集整理的java添加文字水印插件_java之io添加文字水印的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux java 安装 gi_gi的
- 下一篇: mysql省市县三级互动_mysql+a