在我的类UriCodec.java中,但是当我使用javac(jdk6)编译此类错误时。例如:javac UriCodec.java java代码:
import java.io.ByteArrayOutputStream;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.Charsets;
public abstract class UriCodec {
protected abstract boolean isRetained(char c);
public final String encode(String s, Charset charset) {
// Guess a bit larger for encoded form
StringBuilder builder = new StringBuilder(s.length() + 16);
appendEncoded(builder, s, charset, false);
return builder.toString();
}
public final void appendEncoded(StringBuilder builder, String s) {
appendEncoded(builder, s, Charsets.UTF_8, false);
}
public final void appendPartiallyEncoded(StringBuilder builder, String s) {
appendEncoded(builder, s, Charsets.UTF_8, true);
}
public static String decode(String s) {
return decode(s, false, Charsets.UTF_8);
}
private static void appendHex(StringBuilder builder, String s, Charset charset) {
for (byte b : s.getBytes(charset)) {
appendHex(builder, b);
}
}
private static void appendHex(StringBuilder sb, byte b) {
sb.append('%');
sb.append(Byte.toHexString(b, true));
}
}
错误代码:
import java.nio.charset.Charsets;
^
UriCodec.java:140: Can not find symbol
symbol: Variable Charsets
location: class com.android.exchange.utility.UriCodec
appendEncoded(builder, s, Charsets.UTF_8, false);
^
UriCodec.java:144: Can not find symbol
symbol: Variable Charsets
location: class com.android.exchange.utility.UriCodec
appendEncoded(builder, s, Charsets.UTF_8, true);
^
UriCodec.java:203: Can not find symbol
symbol: Variable Charsets
location: class com.android.exchange.utility.UriCodec
return decode(s, false, Charsets.UTF_8);
^
UriCodec.java:214: Can not find symbol
symbol: Method toHexString(byte,boolean)
location: class java.lang.Byte
sb.append(Byte.toHexString(b, true));
^
5 error
类UriCodec.java在eclipse中正确编译,但是使用javac UriCodec.java不正确。谁能告诉我为什么?