Java DecimalFormat Scientific Notation Question

I'm using Java's DecimalFormat class to print out numbers in Scientific Notation. However, there is one problem that I have. I need the strings to be of fixed length regardless of the value, and the sign on the power of ten is throwing it off. Currently, this is what my format looks like: DecimalFormat format = new DecimalFormat("0.0E0"); This gives me the following combinations: 1.0

Java DecimalFormat科学记数法问题

我使用Java的DecimalFormat类以科学记数法打印出数字。 但是,我有一个问题。 无论价值如何,我都需要这些字符串的长度是固定的,而十的幂的符号会把它扔掉。 目前,这是我的格式: DecimalFormat format = new DecimalFormat("0.0E0"); 这给了我以下组合:1.0E1,1.0E-1,-1.0E1和-1.0E-1。 我可以使用setPositivePrefix来获得:+ 1.0E1,+ 1.0E-1,-1.0E1和-1.0E-1,或者我喜欢的任何东西,但它不会影响力量的符号!

Is there an easy way to encrypt a java object?

I'd like to store a serialized object to a file however I'd like to make it encrypted. It doesn't need to be really strong encryption. I just want something easy (preferably a couple lines of code max)that will make it a bit more difficult for someone else to load. I've looked into SealedObject but the key's are holding me up. Ideally I'd like to just pass a String as

有没有简单的方法来加密一个Java对象?

我想将一个序列化的对象存储到一个文件中,但是我想将其加密。 它不需要非常强大的加密。 我只想要一些简单的东西(最好是几行代码),这会让其他人加载时更加困难。 我已经看过SealedObject,但是关键在阻止我。 理想情况下,我想仅传递一个字符串作为加密/解密对象的密钥。 有什么建议么? 试试这个代码: String fileName = "result.dat"; //some result file //You may use any combination, but you should use the

How can I normalize the EOL character in Java?

I have a linux server and many clients with many operating systems. The server takes an input file from clients. Linux has end of line char LF, while Mac has end of line char CR, and Windows has end of line char CR+LF The server needs as end of line char LF. Using java, I want to ensure that the file will always use the linux eol char LF. How can I achieve it? Combining the two answers (b

我如何规范Java中的EOL字符?

我有一个Linux服务器和许多操作系统的客户端。 服务器从客户端获取输入文件。 Linux的行尾有char LF,而Mac的行尾是char CR,而Windows的行结束是char CR + LF 服务器需要行尾字符LF。 使用java,我想确保该文件将始终使用linux eol char LF。 我怎样才能实现它? 结合两个答案(Visage&eumiro): 编辑:在阅读评论后。 线。 System.getProperty(“line.separator”)没有用。 在将文件发送到服务器之前,请打开

Output stream over a StringBuilder

This question already has an answer here: Get an OutputStream into a String 5 answers So you are wanting output written to the stream to go to a StringBuffer instead. I am assuming you are doing this because an OutputStream is required somewhere else. You could use ByteArrayOutputStream, but if you want to preserve the StringBuffer behavior, you might simply wrap a StringBuffer in a subclas

通过StringBuilder输出流

这个问题在这里已经有了答案: 获取一个OutputStream为一个字符串5个答案 所以你想要输出写入到流而不是StringBuffer。 我假设你这样做是因为OutputStream需要在其他地方。 你可以使用ByteArrayOutputStream,但是如果你想保留StringBuffer行为,你可以简单地将一个StringBuffer包装在OutputStream的子类中,就像这里的代码一样: http://geronimo.apache.org/maven/specs/geronimo-javamail_1.4_spec/1.6/apidocs/src-h

Char array to byte array in UTF

I have a little question. I have to encode char array with UTF-8 and get the byte array equivalent of it by using Java. Converting the char array to String and than getting the byte array is not an option, String must be avoided, because of security concerns. If I use byte[] encoded = Charset.forName("UTF-8").encode(CharBuffer.wrap(toBeEncoded)).array(); When the length of the input array is

字符数组中的字符数组以UTF格式表示

我有一个小问题。 我必须使用UTF-8对char数组进行编码,并通过使用Java来获得与它相同的字节数组。 将char数组转换为String而不是获取字节数组不是一个选项,因为安全考虑,必须避免使用String。 如果我使用 byte[] encoded = Charset.forName("UTF-8").encode(CharBuffer.wrap(toBeEncoded)).array(); 当输入数组的长度大于9个符号时,输出数组有一个空的额外元素。 如果长度更长,则会有更多空元素。 然后我解码它,我

How to convert from character positions to byte postions in UTF

I have UTF-8 encoded text file. I can read it by chars. Each char can be either one byte or multibyte. How can I know where one byte was readen and whet it was readen more than one byte? Count the bytes while reading the char s. For each char c : if(c<128) bytesCount++; else if (c<2048) bytesCount+=2; else bytesCount+=3; See also encodeing definition wikipedia URF8

如何将字符位置转换为UTF中的字节位置

我有UTF-8编码的文本文件。 我可以通过字符读取它。 每个字符可以是一个字节或多个字节。 我怎么知道一个字节重新存放的地方,并且它重新存储了多于一个字节? 在读取char计算字节数。 对于每个char c : if(c<128) bytesCount++; else if (c<2048) bytesCount+=2; else bytesCount+=3; 另请参阅编码定义维基百科URF8

Android APP, crashes Catlog provided, Thread exception

I started on my android app again, and now it shows this error below. I can provide any information needed to fix the problem. 05-12 12:26:30.858 3799-3845/amh.communication.testapp E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1 Process: amh.communication.testapp, PID: 3799 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(As

Android APP,崩溃Catlog提供,线程异常

我再次开始在我的Android应用程序,现在它显示下面的错误。 我可以提供解决问题所需的任何信息。 05-12 12:26:30.858 3799-3845 / amh.communication.testapp E / AndroidRuntime: 致命例外:AsyncTask#1 过程:amh.communication.testapp,PID:3799 java.lang.RuntimeException:执行doInBackground()时发生错误 在android.os.AsyncTask $ 3.done(AsyncTask.java:304) 在java.util.concurrent.FutureTask

No class found in android studio

i imported my projected from eclipse to android studio it was working fine and in android studio it works in emulator but in real device here is log 05-04 08:14:14.989 8986-9070/com.rcmbusiness E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.rcmbusiness, PID: 8986 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTas

在android studio中找不到类

我从eclipse导入我的投影到android工作室,它工作的很好,在android工作室它在模拟器中工作,但在真实的设备 这里是日志 05-04 08:14:14.989 8986-9070 / com.rcmbusiness E / AndroidRuntime:致命异常:AsyncTask#1进程:com.rcmbusiness,PID:8986 java.lang.RuntimeException:在android中执行doInBackground()时发生错误.os.AsyncTask $ 3.done(AsyncTask.java:300)at java.util.concurrent.FutureTask.finishC

Error when using fragement and asynctask

I am trying to get a list of data from MySQL that is hosted then return the result in a listview. But I am not able to make it when using fragments. I am getting the following error: com.example.test.myapp E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.exampletest.myapp, PID: 31491 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.Async

使用fragement和asynctask时出错

我试图从托管的MySQL中获取数据列表,然后以列表视图返回结果。 但是在使用碎片时我无法做到。 我收到以下错误: com.example.test.myapp E / AndroidRuntime:致命异常:AsyncTask#1进程:com.exampletest.myapp,PID:31491 java.lang.RuntimeException:在android.os.AsyncTask $ 3执行doInBackground()时发生错误。 java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)在java.util.concurrent

Best way to read a large file containing a single

I did a small experiment for the Reading files having single line string and multiple line strings. The singleLine file is 198890 lengthed and the multiLine file is 208890 lengthed. I tested them with six methods as follows and got the timings and String length that they have read. Here I've mentioned the Test method, Result and the Implementations. My actual consideration is reading a l

读取包含单个文件的大文件的最佳方法

我为具有单行字符串和多行字符串的Reading文件做了一个小实验。 单线文件长度为198890,多线文件长度为208890。 我用以下六种方法测试了它们,并获得了它们读取的时间和字符串长度。 这里我提到了测试方法,结果和实现。 我的实际考虑是阅读一个包含单行文本的大文件。 根据结果​​,它看起来像IO utils比其他人好。 那么,除了我在下面实现的方法(如果有的话)之外,我可以使用的最佳方式是什么。 结果:(时间以秒为单