我有代码将文件复制到另一个位置.
public static void copyFile(String sourceDest, String newDest) throws IOException {
File sourceFile = new File(sourceDest);
File destFile = new File(newDest);
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然复制小块,比如300-400 Mb,但一切都像魔术一样.但是,当我尝试复制1.5 Gb大小的文件时,它失败了.堆栈是:
run:12.01.2011 11:16:36 FileCopier main SEVERE:复制文件时发生异常.再试一次.java.io.IOException:在sun.nio.ch.FileChannelImpl的sun.nio.ch.FileChannelImpl.transferFromFileChannel(FileChannelImpl.java:527)的sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:748)上映射失败.transferFrom(FileChannelImpl.java:590)FileCopier.copyFile(FileCopier.java:64)at FileCopier.main(FileCopier.java:27)引起:java.lang.OutOfMemoryError:地图在sun.nio.ch.FileChannelImpl失败sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:745)的.map0(Native方法)... 4更多BUILD SUCCESSFUL(总时间:0秒)
我没有和NIO密切合作过.你能帮帮我吗?非常感谢你提前.
我正在使用调用beginthreadex,endthreadex在Visual Studio C++中进行一些多线程编程.
我创建了一个子线程thread1.子线程运行在一个永不退出的函数上,因为它具有无限循环.现在,如果父线程因错误终止或成功完成,子线程是否也会退出?我的疑问是 - 即使在主程序退出后,是否存在子线程仍处于活动状态的情况?
对于linux,这种情况应该怎样?
正如标题所说.以下是我的代码框架.
class CLASS
{
public:
void A();
private:
DWORD WINAPI B(LPVOID);
};
void CLASS::A()
{
DWORD (WINAPI CLASS::*thread)(LPVOID) = &CLASS::B;
...
CreateThread(NULL, 0, thread, &arg, 0, NULL);
...
}
Run Code Online (Sandbox Code Playgroud)
函数B需要CLASS的成员变量.
但是当我编译它时,我有一个错误代码.
它"无法将参数3从'DWORD(__ stdcall CLASS ::*)(LPVOID)'转换为'LPTHREAD_START_ROUTINE'"或类似的东西.
我不知道英语环境是否相同.
有人可以帮忙吗?
我通常使用UUID类生成唯一ID.如果这些ID仅由技术系统使用,它们可以正常工作,它们不关心它们有多长:
System.out.println(UUID.randomUUID().toString());
> 67849f28-c0af-46c7-8421-94f0642e5d4d
Run Code Online (Sandbox Code Playgroud)
有没有一种很好的方法来创建用户友好的唯一ID(比如来自tinyurl的那些)比UUID短一点?用例:您希望通过邮件向您的客户发送ID,然后客户访问您的网站并将该号码输入表单,如凭证ID.
我假设UUID在UUID的128位范围的整个范围内均等地生成.那么仅仅使用较低的64位是圣人吗?
System.out.println(UUID.randomUUID().getLeastSignificantBits());
Run Code Online (Sandbox Code Playgroud)
欢迎任何反馈.
当我尝试编译以下代码时
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using NHibernate;
namespace NewNHTest
{
class A
{ }
class Program
{
static void Main(string[] args)
{
ISession session;
var q = session.Query<A>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
'NHibernate.ISession' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'NHibernate.ISession' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
NHibernate.dll版本是3.0.0.4000.
.Net版本的项目是3.5.
我究竟做错了什么?
谢谢您的帮助!
我现在正在互联网上搜索一段时间,似乎目前几乎没有办法为Android平台开发XNA游戏.
你们有没有人知道将XNA游戏移植到Android平台的任何好方法?
XNATouch它还没有monodroid的端口,还有其他任何项目吗?
我有一个自定义的asp.net mvc类验证属性.我的问题是如何对其进行单元测试?测试类具有属性是一回事,但这实际上不会测试其中的逻辑.这是我想测试的.
[Serializable]
[EligabilityStudentDebtsAttribute(ErrorMessage = "You must answer yes or no to all questions")]
public class Eligability
{
[BooleanRequiredToBeTrue(ErrorMessage = "You must agree to the statements listed")]
public bool StatementAgree { get; set; }
[Required(ErrorMessage = "Please choose an option")]
public bool? Income { get; set; }
Run Code Online (Sandbox Code Playgroud)
.....为简洁而删除}
[AttributeUsage(AttributeTargets.Class)]
public class EligabilityStudentDebtsAttribute : ValidationAttribute
{
// If AnyDebts is true then
// StudentDebts must be true or false
public override bool IsValid(object value)
{
Eligability elig = (Eligability)value;
bool ok …Run Code Online (Sandbox Code Playgroud) 我有一个从appwidgetprovider扩展的appwidget.
我创建了一个名为main_layout.xml的布局xml文件并添加了一个按钮.如果我开发了listActivity,我会使用以下路径到达此按钮:R.layout.main_layout.button01.
(Button)findViewById(R.layout.main_layout.button01)
Run Code Online (Sandbox Code Playgroud)
Activity类有一个名为findViewById()的成员方法,但appwidgetprovider却没有.
如何在布局中找到我的按钮?
对不起我的英语不好
这是一个概念验证问题。我正在设计一个 GUI,用于在飞行模拟应用程序中编辑空中交通参与者的航路点。在当前的概念中,所选航路点的参数显示在一堆文本框中。该输入掩码既充当数据视图又充当编辑掩码。编辑字段后,用户可以:
如果仅需要为新路径点更改某些参数子集,则此设计可以避免重新输入数据。
只有一个问题:在哪里插入路径点?我的答案是“另存为新”按钮上的下拉菜单,其中包含以下菜单项:
最后一项是棘手的。索引位置需要由用户输入,我想避免弹出窗口只要求单个值。
我的想法是:将文本框嵌入到菜单项中。
这种方法在 QT 或 wxWidgets 中可行吗?您对 GUI 设计有何看法?
问候,阿恩
PS:请注意,这一切都处于概念阶段。该小组甚至还没有决定使用哪种 GUI 框架:Qt 或 wxWidgets。
我使用mod_jk设置在端口80上运行apache2和tomcat6(未从apt存储库安装,手动下载和安装).访问jsp servlet页面,将浏览器指向http://myapp.mydomain.com/(虚拟主机在tomcat(server.xml)和apache中完成).在部署期间,当tomcat关闭(pkill -9 java或/etc/init.d/tomcat stop)时,我正在尝试将tomcat的错误页面503重定向到自定义错误页面.
我的apache的Document Root是/ var/www/so我把它放在apache2.conf文件的下面
ErrorDocument 503 maintenance.html并在/ var/www下创建了一个文件maintenance.html.当我测试停止tomcat并且我将页面重定向到maintenance.html而没有更改url但是没有显示实际页面,而是maintenance.html在浏览器上显示文件名.任何人都可以帮我正确配置当tomcat关闭时重定向到正确的maintenance.html页面的apache吗?