我想将c:\ttt.txt变成c:\\ttt.txt
帮我看看那而错了,本来想用split,但是编出来的程序老是有异常,改了一下还是不对.
package com.topfounder.eclipse;
import java.util.*;
import java.io.*;
public class JavaTest {
static String getFilePath(String s)
{
int j=0;
String filePath=null;
ArrayList array=new ArrayList();
StringTokenizer st=new StringTokenizer(s.trim(),"\\");
while(st.hasMoreTokens())
{
array.add(st.nextElement());
}
for(int index=0;index<array.size()-1;index++)
{
filePath=filePath+array.get(index)+"\\";
}
filePath=filePath+array.get(array.size()-1);
return filePath; }
public static void main(String[] args)
{
String s=getFilePath("c:\ttt.txt");
System.out.println(s); }}
帮我看看那而错了,本来想用split,但是编出来的程序老是有异常,改了一下还是不对.
package com.topfounder.eclipse;
import java.util.*;
import java.io.*;
public class JavaTest {
static String getFilePath(String s)
{
int j=0;
String filePath=null;
ArrayList array=new ArrayList();
StringTokenizer st=new StringTokenizer(s.trim(),"\\");
while(st.hasMoreTokens())
{
array.add(st.nextElement());
}
for(int index=0;index<array.size()-1;index++)
{
filePath=filePath+array.get(index)+"\\";
}
filePath=filePath+array.get(array.size()-1);
return filePath; }
public static void main(String[] args)
{
String s=getFilePath("c:\ttt.txt");
System.out.println(s); }}
解决方案 »
- 怎样把两条sql语句的查询信息都放到JTable里
- 帮帮忙啊。。怎样利用eclipse打开已有的java文件并运行 。。在线等待中
- 100分求个在LinkedList列表里删除重复的元素的函数
- 求助关于如何用java的界面调用已完成的c/c++程序
- java配置ODBC
- 问一个Swing做界面算是设计模式方面的问题,语言上应如何去实现
- 我编的一个GUI程序,为什末在启动后需调整一下窗口大小才能显示,如何解决?
- simple question
- 求救:用java通过pop3协议如何获取信件正文内容和附件内容.
- double 转 String
- 你们的工资多少呀?
- jvm都Down拉,finalize()还会执行吗?
import java.util.StringTokenizer;/**
* URL:http://community.csdn.net/Expert/topic/4689/4689753.xml?temp=.5499384
*
* @author pangpang
* @version 2006/04/16
*/
public class JavaTest { static String getFilePath(String s) { String filePath = "";
ArrayList<Object> array = new ArrayList<Object>();
StringTokenizer st = new StringTokenizer(s.trim(), "\\");
array.add(st.nextElement());
while (st.hasMoreTokens()) {
array.add(st.nextElement());
}
for (int index = 0; index < array.size()-1; index++) {
filePath = filePath + array.get(index) + "\\\\"; }
filePath = filePath + array.get(array.size() - 1);
return filePath;
} public static void main(String[] args) { String s = getFilePath("c:\\ttt.txt");
System.out.println(s); }}注意转义字符!!