我想输入到csv文件.
我的输入如下所示
String string ="hi,this is user";
但是当我输入到csv文件时,逗号被视为分隔符,它被写入两个单元格.一个单元格中的"hi"和另一个单元格中的"this is user".
但我希望整个字符串都在一个单元格中.
我怎样才能做到这一点.
请帮我.
FileWriter writer = new FileWriter("D:/Workspace/Sample2.csv");
PrintWriter out = new PrintWriter(writer);
String names="[hasds,jash.jahd,jash]";
out.append(names);
out.flush();
}
Run Code Online (Sandbox Code Playgroud) 我试着学习c-library的qsort功能stdlib.这甚至提供c++.但我不明白如何使用它们来排序c++字符串.我不确定sizeof()操作员的参数应该是什么,以及我的compare_str代码是否正确.我试过这段代码:
#include<iostream>
#include<cstdlib>
using namespace std;
#include<string>
int compare_str( const void *a, const void *b){
string obj = (const char*)a;
string obj1 = (const char*)b;
return obj.compare(obj1);
}
int main(){
string obj[4] = {"fine", "ppoq", "tri", "get"};
qsort(obj, 4, sizeof(obj[0].length()), compare_str);
for( int i=0; i<4; i++)
cout<<obj[i]<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的输出是:
ppoq
tri
get
fine
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚错误.请帮忙.
我有一长串数字,
String strNumbers = "123456789";
Run Code Online (Sandbox Code Playgroud)
我需要得到一个int[].
我用这个方法得到它:
public static int[] getIntArray(strNumbers)
{
String[] strValues = strNumbers.split("");
int[] iArr = new int[strValues.length];
for(int i = 0; i < strValues.length; i++)
{
iArr[i] = Integer.parseInt(strValues[i]);
}
return iArr;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:java.lang.NumberFormatException:对于输入字符串:""
我的猜测是我无法以这种方式拆分String.我尝试了各种各样的逃避或正则表达但没有任何作用.
有人可以帮忙吗?
我在看代码new FileInputStream("config.properties").
我在我的项目的多个地方有相同的文件"config.properties"(做Windows文件搜索),我现在很困惑这个函数调用引用了哪一个.我怎样才能知道文件的绝对路径?
我在互联网上找到了这个,但这个位置看起来不是正确的答案.
"ClassName".class.getProtectionDomain().getCodeSource().getLocation().getPath()但这看起来并没有.如果我错了,你可以纠正吗?