我在尝试将我的支票样式导入IDEA 14时遇到了问题.这就是我所做的:
replaceAll("\\s+")和之间有什么区别replaceAll("\\\\s+")?通常我会使用\\s+但有时我会看到\\\\s+.
我是Java的新手.
我有以下问题:方法readLine()或者nextLine(),nextInt()等抛出异常:NullPointerException.
我使用NetBeans IDE(如果重要的话).
public static void Reading()
{
String qq;
qq = System.console().readLine();
System.console().printf(qq);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试解析我的文件,它将所有数据保存为二进制形式.如何从偏移量为M的文件中读取N个字节?然后我需要使用它将其转换为String new String(myByteArray, "UTF-8");.谢谢!
这是一些代码:
File file = new File("my_file.txt");
byte [] myByteArray = new byte [file.lenght];
Run Code Online (Sandbox Code Playgroud)
UPD 1:我看到的答案并不合适.我的文件以字节形式保存字符串,例如:当我在我的文件中放入字符串"str"时,它实际上打印出类似[B @ 6e0b ...在我的文件中的smth.因此,我需要再次从这个字节码中获取我的字符串"str".
UPD 2:当我发现问题出现时,我使用toString():
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(System.getProperty("db.file")), true), "UTF-8")));
Iterator it = storage.entrySet().iterator();//storage is a map<String, String>
while (it.hasNext()){
Map.Entry pairs = (Map.Entry)it.next();
String K = new String(pairs.getKey().toString());
String V = new String(pairs.getValue().toString);
writer.println(K.length() + " " + K.getBytes() + " " + V.length() + " " + V.getBytes());//this is just the format …Run Code Online (Sandbox Code Playgroud)