我试图替换String中的字符,它有时会起作用,而且大多数时候都不起作用.
我尝试了以下方法:
String t = "[javatag]";
String t1 = t;
String t2 = t;
t.replace("\u005B", "");
t.replace("\u005D", "");
t1.replace("[", "");
t1.replace("]", "");
t2.replace("\\]", "");
t2.replace("\\[", "");
System.out.println(t+" , "+t1+" , "+t2);
Run Code Online (Sandbox Code Playgroud)
结果输出仍然是" [javatag] , [javatag] , [javatag]"而没有"["和"]"被替换.
我应该怎么做才能取代那些"["和"]"字符?
我试图从传入的智能卡APDU读取数据并返回相同的传入消息,同时还将ASCII字"响应"附加到消息的前面.我正在获得一个6F00地位.我该如何修复代码?
我的代码:
private void repeat(APDU apdu) {
byte[] buffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
byte[] incomingMsg = getData(buffer);
if ((short) incomingMsg.length != (short) 0) {
apdu.setOutgoing();
// Send back the "respond " + "<incoming message" back
byte[] respMsg = {0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x20};
byte[] outgoingMsg = new byte[(short) (incomingMsg.length + respMsg.length)];
ArrayLogic.arrayCopyRepack(respMsg, (short) 0, (short) respMsg.length, outgoingMsg, (short) 0);
ArrayLogic.arrayCopyRepack(incomingMsg, (short) 0, (short) incomingMsg.length, outgoingMsg, (short) respMsg.length);
buffer = outgoingMsg;
apdu.setOutgoingAndSend((short) 0, (short) outgoingMsg.length);
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个java应用程序,我希望我的Windows批处理文件执行.我可以知道为什么以下批处理文件代码不起作用以及我如何纠正它们?在继续检查64位Java之前,脚本应首先检查32位Java.
我还希望我的批处理文件能够处理Java 6及更高版本,并且包含JRE或JDK环境.我如何修改我的批处理文件来处理它们.
批处理脚本:
@ECHO OFF
IF EXIST "C:\Program Files (x86)\Java" (
start C:\Program Files (x86)\Java\jre7\bin\java -jar %~dp0\JavaShop.jar
) ELSE (
IF EXIST "C:\Program Files\Java" C:\Program Files\Java\jre6\bin\java -jar %~dp0\JavaShop.jar
ELSE ECHO Java software not found on your system. Please go to http://java.com/en/ to download a copy of Java.
PAUSE
)
Run Code Online (Sandbox Code Playgroud) 我正在编写一个配置文件解析器,并在我的Config.php文件中有一个名为getVals()的函数,但显然当我在测试中调用它时会抛出"未定义函数"错误.
config.php文件
<?php
require_once '../extlib/pear/Config/Lite.php';
class Config {
private $config;
function __construct($conf) {
$this->config = new Config_Lite();
echo "calling open...<br>";
$this->open($conf);
echo "open done...<br>";
}
function open($cfile) {
if (file_exists($cfile)) {
$this->config->read($cfile);
} else {
file_put_contents($cfile, "");
$this->open($cfile);
}
}
function getVals() {
return $this->config;
}
function setVals($group, $key, $value) {
$this->config->set($group, $key, $value);
}
function save() {
$this->config->save();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
cfgtest.php中的测试类
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../util/Config.php';
$cfile = "../../test.cfg";
$cfg = new Config($cfile);
if (is_null($cfg)) {
echo …Run Code Online (Sandbox Code Playgroud) 我有一个方法将单个字节插入字节缓冲区,在构建和清理Java Card CAP文件期间,它会抛出错误.
码:
private void appendOutputBuffer(byte msg) {
ArrayLogic.arrayCopyRepack(msg, (short) 0, (short) 0, outputBuffer, (short) outputBuffer.length);
}
Run Code Online (Sandbox Code Playgroud)
错误:
error: line 163: sctest: class java.lang.Byte not found in export file lang.exp.
error: line 163: sctest: method valueOf(byte) of class java.lang.Byte not found in export file lang.exp or the method signature has changed.
error: line 163: sctest: class java.lang.Byte not found in export file lang.exp.
error: line 163: sctest: class java.lang.Byte in return type of method java.lang.Byte.valueOf(byte) not found.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我试图从类文件动态加载.下面的代码无法调用类中的方法.
public static void main(String[] args) {
try {
File loadPath = new File("C:/loadtest/");
URL url = loadPath.toURI().toURL();
URL[] urls = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
Class cls = cl.loadClass("TesterClass");
System.out.println("Classname: " + cls.getName());
Method[] m = cls.getMethods();
for (Method m1 : m){
try {
System.out.println("Method: " + m1.getName());
if (m1.getName().equals("getName")) {
Object o = m1.invoke(null, null);
System.out.println("o is : " + o);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
} catch (MalformedURLException | ClassNotFoundException e) …Run Code Online (Sandbox Code Playgroud)