小编Chr*_*ung的帖子

Java renameTo在包含内容的文件夹上

只是尝试使用Java重命名文件夹树的根目录.

使用File.renameTo()仅适用于Windows,该文件夹根本没有内容.我似乎无法找到这是否是预期的行为.它似乎没有在文档中提及.

我目前不得不使用递归文件\文件夹复制过程然后删除原始,但这比我希望在文件夹树中更强烈,其中每个节点可能有数百个子节点.

看起来Java 7有Path.moveTo()但我还不能使用7.

我是不是以肮脏的方式做到了,还是有办法让根文件夹名称改变了?

谢谢.

java directory file move

3
推荐指数
1
解决办法
3201
查看次数

自动生成包装以防止"恶意贬低"?

如果在Java中实现接口,则没有什么可以阻止调用者查看您提供的具体实现,转换为该类并调用不在接口中的方法.我相信这被称为"恶意贬低".

防止这种情况的一种方法是创建一个只包含接口方法的包装器,并且不公开它所委托的实现实例.如果没有对私有变量的反思,你应该是安全的.

有没有办法自动创建这种包装器(在运行时,不使用IDE中的代码创建向导,因为仍然会创建需要维护的源文件)?

java delegates code-generation

2
推荐指数
2
解决办法
268
查看次数

无法将类型'System.Collections.Generic.List'隐式转换为'System.Collections.Generic.List

Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List

Error 2 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<Product>' D:\Fortune\App_Code\BL\StoreController.cs 204 45 D:\Fortune\

public static List<Product> GetProductsByCategoryID(int productCategoryId )
{
    FortuneDataContext db = SiteController.GetNewFortuneDataContext();
    List<Product>  prods = (from p in db.Products
                        join pc in db.ProductCategories 
                        on p.ProductCategoryId equals pc.ProductCategoryId 
                        where pc.ParentProductCategoryId == productCategoryId
                        select new
                        {
                           p.ProductId,
                           p.ProductCategoryId,
                           pc.ParentProductCategoryId,               
                           ProductName = p.Name,
                           Category = pc.Name,
                           p.Price,
                           p.ProductYear
                           }).ToList();  
    return prods;

}
Run Code Online (Sandbox Code Playgroud)

我想要选择新的{...}中的所有字段,我喜欢这样的选择,但所有字段都不在Product表中.....

          select new Product
                    {
                       p.ProductId,
                       p.ProductCategoryId,
                       pc.ParentProductCategoryId,               
                       ProductName = p.Name,
                       Category …
Run Code Online (Sandbox Code Playgroud)

asp.net

2
推荐指数
1
解决办法
2万
查看次数

Java java.util.ConcurrentModificationException错误

请允许任何人帮我解决这个问题,这么多天我无法解决这个错误.我尝试使用同步方法和其他方法,但没有工作,所以请帮助我

错误

java.util.ConcurrentModificationException
 at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
 at java.util.AbstractList$Itr.remove(Unknown Source)
 at JCA.startAnalysis(JCA.java:103)
 at PrgMain2.doPost(PrgMain2.java:235)
Run Code Online (Sandbox Code Playgroud)

 public synchronized void startAnalysis() {
        //set Starting centroid positions - Start of Step 1
        setInitialCentroids();
        Iterator<DataPoint> n = mDataPoints.iterator();
        //assign DataPoint to clusters
        loop1:
        while (true) {
            for (Cluster c : clusters)
            {
                c.addDataPoint(n.next());
                if (!n.hasNext())
                    break loop1;
            }
        }

        //calculate E for all the clusters
        calcSWCSS();

        //recalculate Cluster centroids - Start of Step 2
        for (Cluster c : clusters) {
            c.getCentroid().calcCentroid();
        }

        //recalculate E for …
Run Code Online (Sandbox Code Playgroud)

java core

2
推荐指数
1
解决办法
2万
查看次数

使用Java在Gmail帐户上发送电子邮件

我知道这个问题之前会被问到,但我认为这是2 - 3年前,事情发生了变化.现在没有任何代码示例正在运行.我在Java 1.6中尝试以下代码:

Properties props = new Properties();
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("uname","password");
    }
});
session.setDebug(true);
Transport transport = session.getTransport();
InternetAddress addressFrom = new InternetAddress("abc@gmail.com");
MimeMessage message = new MimeMessage(session);
message.setSender(addressFrom);

for (int j = 0; j < 20; j++) {
    message.setSubject("Testing javamail plain"+Math.random());
    message.setContent("This is a test", "text/plain");
    String sendTo [] = …
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
3498
查看次数

验证网址| 预先http://

我想检查用户提交的URL与正则表达式,如果url不以http://或https://开头,那么我想先将http://添加到开头然后保存它.

我有一些代码,但我不知道如何将它合并到我的应用程序中.这段代码会起作用吗?并且我会在允许用户创建链接之前将其合并到我的应用程序中以检查URL.

我已经附上了下面的代码和文件.谢谢

def add_http(link)
  if (link =~ /http[s]?:\/\//)
    link
  else
    "http://#{link}"
  end
end
Run Code Online (Sandbox Code Playgroud)

控制器https://gist.github.com/1279576

_form https://gist.github.com/1279580

型号https://gist.github.com/1279582

ruby regex model-view-controller ruby-on-rails ruby-on-rails-3

2
推荐指数
3
解决办法
2064
查看次数

常见的lisp符号匹配

我有一个以下形式的列表:

((|* bank accounts| (|account 1| |account 2|))
 (|* airline miles| (|account 1| |account 2|))
 .....
 .....)
Run Code Online (Sandbox Code Playgroud)

我不知道怎样用来assoc访问这些符号,因为它们的两边都是"|".

lisp common-lisp

2
推荐指数
1
解决办法
242
查看次数

add1函数从scheme到R5RS

我写了一些代码,但它没有用,因为add1我在Scheme中使用的函数不适用于R5RS.什么可以取代add1R5RS?

scheme racket r5rs

2
推荐指数
1
解决办法
1592
查看次数

如何使用scheme48正确执行程序?

我正在学习Scheme。我想为 Gimp 构建script-fu过滤器,所以我使用tinyscheme来执行我制作的脚本,但似乎tinyscheme的功能非常有限,缺少maxmin和等功能even?。(我希望有人能在这里证明我错了:()

好吧,实际上,我只想用scheme48执行一个Scheme脚本。我怎么做?

例如,如何使用scheme48执行以下文件?

(define (addx inNum inX)
  (if (> (* inNum inX) 999) 0
      (+ (* inNum inX) (addx inNum (+ 1 inX)))))

(display 
  (- (+ (addx 3 1) (addx 5 1)) (addx 15 1)))
Run Code Online (Sandbox Code Playgroud)

linux scheme scheme48

2
推荐指数
1
解决办法
1689
查看次数

方案总和从a到b迭代

我正在尝试编写一个程序,在a和b之间添加所有数字.例如,如果a = 1且b = 5,则该过程将添加1 + 2 + 3 + 4 + 5.这是我到目前为止所拥有的.我想迭代地写这个.谢谢!

(define (sum term a next b)
  (define (iter a result)
    (if (> a b)
        sum
        (iter ?? ??)))
  (iter ?? ??))
Run Code Online (Sandbox Code Playgroud)

iteration scheme

2
推荐指数
1
解决办法
1689
查看次数