小编Rag*_*aja的帖子

如何在包含dot的java中替换String?

我需要替换包含空格和句点的String.我尝试过以下代码:

String customerName = "Mr. Raj Kumar";

customerName = customerName.replaceAll(" ", "");
System.out.println("customerName"+customerName);

customerName = customerName.replaceAll(".", "");
System.out.println("customerName"+customerName); 
Run Code Online (Sandbox Code Playgroud)

但结果是:

customerName Mr.RajKumar

顾客姓名

我从第一个SOP获得了正确的客户名称,但是从第二个SOP我没有得到任何价值.

java string

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

如何在java中获取当前目录?

我试图从java获取我的项目的当前目录.我使用以下代码行来获取路径详细信息.

类型1:

File directory = new File (".");
try {
    System.out.println ("Current directory's canonical path: " 
            + directory.getCanonicalPath()); 
    System.out.println ("Current directory's absolute  path: " 
                + directory.getAbsolutePath());
}catch(Exception e) {
    System.out.println("Exceptione is ="+e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

类型2:

String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
Run Code Online (Sandbox Code Playgroud)

从主类执行上面的代码我得到项目目录.当我从服务器端执行时,得到"当前dir使用System:D:\ Apache Tomcat 6.0.16\bin".但我的项目位于D:\Apache Tomcat 6.0.16\wepapps\SampleStructs.

请给我任何建议,并帮助我解决这个问题.

java linux directory struts2 java-ee

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

标签 统计

java ×2

directory ×1

java-ee ×1

linux ×1

string ×1

struts2 ×1