java如何用eclipse编写代码_如何为eclipse编写代码模板?

我有一些我需要的特定代码,以便能够拥有我不想每次都写的某些I / O内容,而我只是想能够添加一个java类,以便它已经具有该代码在那里,我尝试过:

/*

ID: my_id

PROG: ${filename}

LANG: JAVA

*/

import java.util.*;

import java.io.*;

import java.net.InetAddress;

public class ${filename} {

static class InputReader {

private StringTokenizer st = null;

private BufferedReader br = null;

public InputReader(String fileName) throws Exception {

try {

br = new BufferedReader(new FileReader(fileName));

} catch (Exception e) {

e.printStackTrace(System.err);

}

}

public InputReader(InputStream in) {

try {

br = new BufferedReader(new InputStreamReader(in), 32768);

} catch (Exception e) {

e.printStackTrace(System.err);

}

}

public String next() {

while (st == null || !st.hasMoreTokens()) {

try {

st = new StringTokenizer(br.readLine());

} catch (Exception e) {

e.printStackTrace(System.err);

}

}

return st.nextToken();

}

public int nextInt() {

return Integer.parseInt(next());

}

}

public static void main(String[] args) throws Exception {

InetAddress addr = InetAddress.getLocalHost();

String hostname = addr.getHostName();

boolean isLocal = hostname.equals("paulpc");

String location = null;

InputReader in = null;

PrintWriter out = null;

if (!isLocal) {

location = ${filename}.class.getProtectionDomain().getCodeSource().getLocation().getPath();

in = new InputReader(location + "/" + "${filename}.in");

out = new PrintWriter(new FileWriter(location + "/" + "${filename}.out"));

} else {

in = new InputReader(System.in);

out = new PrintWriter(System.out);

}

solve(in, out);

out.close();

}

public static void solve(InputReader in, PrintWriter out) {

}

}

基本上这个东西需要在xml中,但我不知道如何正确编写它,我以为在任何地方编写$都会这样做,但它不起作用 . 总而言之,我希望文件的名称写在我写“$”的地方,我该怎么办呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值