String.Split便于在分隔符上拆分多个部分的字符串.
我该如何继续仅在第一个分隔符上拆分字符串.我有一个字符串
"Time: 10:12:12\r\n"
Run Code Online (Sandbox Code Playgroud)
我想要一个看起来像的阵列
{"Time","10:12:12\r\n"}
Run Code Online (Sandbox Code Playgroud) 我正在格式化ResultSet输出到CSV文件.因此,我真的不关心结果集的Java类型,除了可能知道它是文本还是数字.
请问JDBC保证的getString总会给的值的字符串表示,至少对于单值(我不需要关心自己有关java.sql.Types.ARRAY,java.sql.Types.JAVA_OBJECT和其他几个人).
例如,给定resultSetMetaData.getColumnType(i)是a Types.FLOAT或a Types.BIGDECIMAL.将rs.GetString(i)总是产生一些字符串?
即是否有getString会抛出一个SQLException或者当getXXX给我的值时返回null?
我正在查看工具的输出,将数据库表转储到XML.其中一列被命名为64kbit,该工具就是这样编码的,我需要复制它:
<_x0036_4kbit>0</_x0036_4kbit>
Run Code Online (Sandbox Code Playgroud)
这是某种标准编码吗?我在哪里可以了解更多信息?
我有一个ClickOnce应用程序.在一台计算机上 - Windows 7(适用于其他计算机)升级失败 - 安装由Apache提供.整个日志都很长,但唯一的错误是:
ERROR DETAILS
Following errors were detected during this operation.
* [26.01.2010 10:55:07] System.Runtime.InteropServices.COMException
- A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)
- Source: System.Deployment
- Stack trace:
at System.Deployment.Internal.Isolation.IStore.Transact(IntPtr
cOperation, StoreTransactionOperation[] rgOperations, UInt32[] rgDispositions, Int32[] rgResults)
at System.Deployment.Internal.Isolation.Store.Transact(StoreTransactionOperation[] operations, UInt32[] rgDispositions, Int32[] rgResults)
at System.Deployment.Application.ComponentStore.SubmitStoreTransaction(StoreTransactionContext storeTxn, SubscriptionState subState)
at System.Deployment.Application.ComponentStore.SubmitStoreTransactionCheckQuota(StoreTransactionContext storeTxn, SubscriptionState subState)
at System.Deployment.Application.ComponentStore.CommitApplication(SubscriptionState subState, CommitApplicationParams commitParams)
at System.Deployment.Application.SubscriptionStore.CommitApplication(SubscriptionState& subState, CommitApplicationParams commitParams)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc) …Run Code Online (Sandbox Code Playgroud) 如下所示,我可以通过两种简单的方式制作流式复印机(介绍Apache Commons或类似的).我应该选择哪一个,为什么?
public class StreamCopier {
private int bufferSize;
public StreamCopier() {
this(4096);
}
public StreamCopier(int bufferSize) {
this.bufferSize = bufferSize;
}
public long copy(InputStream in , OutputStream out ) throws IOException{
byte[] buffer = new byte[bufferSize];
int bytesRead;
long totalBytes = 0;
while((bytesRead= in.read(buffer)) != -1) {
out.write(buffer,0,bytesRead);
totalBytes += bytesRead;
}
return totalBytes;
}
}
Run Code Online (Sandbox Code Playgroud)
VS
public class StreamCopier {
public static long copy(InputStream in , OutputStream out)
throws IOException {
return this.copy(in,out,4096);
}
public static long copy(InputStream …Run Code Online (Sandbox Code Playgroud) 当用户使用右上角X或Alt + F4关闭它时,System.Windows.Forms.Form会自动释放吗?表单显示为form.Show(this),而不是form.ShowDialog(...);
我正在尝试调试一个获取InvalidCastException的应用程序.失败的路线是
decimal d = (decimal)row[denominator];
Run Code Online (Sandbox Code Playgroud)
在调试器中检查这个(见下面的截图),row [denominator]保持一个值为8.0的double,据我所知.Surly应该没有任何问题将其转换为小数?
('row'类型来自3.派对库,它再次来自MySQL的数据.当针对较旧的MySQL服务器进行测试时会出现问题,该服务器显然会在MySQL 5.1上将某些聚合返回为double vs decimal - 同样的查询,完全相同数据库中的数据副本)
Visual Studio截图http://img18.imageshack.us/img18/3897/invaldicast.png
有关如何进一步调查此问题的任何帮助?
最近我一直在编写类似这样的代码:
messagehandler.h:
#include "message.h"
class MessageHandler {
public:
virtual ~MessageHandler() {}
virtual void HandleMessage(Message *msg) = 0:
};
Run Code Online (Sandbox Code Playgroud)
persistmessagehandler.h:
MessageHandler *CreatePersistMessageHandler();
Run Code Online (Sandbox Code Playgroud)
persistmessagehandler.cpp:
#include "messagehandler.h"
#include "persist.h"
class PersistMessageHandler : public MessageHandler {
private:
PersistHandle ph;
size_t count;
InternalCheck();
public:
PersistMessageHandler(int someParam);
virtual ~PersistMessageHandler ();
virtual void HandleMessage(Message *msg):
};
PersistMessageHandler::PersistMessageHandler(int someParam)
{
ph.Initialize();
}
... rest of implementation.
MessageHandler *CreatePersistMessageHandler(int someParam)
{
return new PersistMessageHandler(someParam);
}
Run Code Online (Sandbox Code Playgroud)
这里的原因是隐藏PersistMessageHandler.客户端不需要包含PersistMessageHandler类的头,包含实现可能需要的所有包含和类型,以及更清晰地分离接口和实现..无论如何它总是会被动态分配,
所有PersistMessageHandler用户只需调用CreatePersistMessageHandler(..); 直接或间接从工厂获得一个.
但.我没有看到这种方法在其他地方使用得太多.以上是好的做法吗?对于简单的案例,还有其他/更好的选择吗?
考虑一个简单的案例
public class Test {
public String myString;
}
Run Code Online (Sandbox Code Playgroud)
有什么办法可以告诉XmlSerializer在序列化时对base64编码myString吗?
我已经扩展FutureTask,从java.util.concurrent提供的回调来跟踪提交的任务的执行ExecutorService.
public class StatusTask<V> extends FutureTask<V> {
private final ITaskStatusHandler<V> statusHandler;
public StatusTask(Callable<V> callable, ITaskStatusHandler<V> statusHandler){
super(callable);
if (statusHandler == null)
throw new NullPointerException("statusHandler cannot be null");
this.statusHandler = statusHandler;
statusHandler.TaskCreated(this);
}
@Override
public void run() {
statusHandler.TaskRunning(this);
super.run();
}
@Override
protected void done() {
super.done();
statusHandler.TaskCompleted(this);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我看到的是,如果任务被提交,但最终排队等待cancel(true);任务 - run()方法仍然被调用 - 并且FutureTask.run()(可能)检查任务被取消并且不调用被包装的可调用对象.
我应该这样做吗
@Override
public void run() {
if(!isCancelled()) {
statusHandler.TaskRunning(this);
super.run();
}
}
Run Code Online (Sandbox Code Playgroud)
或者我还应该打电话super.run()?这两种方法在检查取消和做某事之间似乎容易受到竞争条件的影响......任何想法都会受到重视.