使用与时间相对应的Csv文件获得奇怪的输出(Getting weird output with Csv file corresponding with time)
当我在csv文件中扫描时,我得到了奇怪的输出,用“,”分隔它,对于每行的长度,我用i +“:”将第i个元素附加到printwriter。我的原始输入看起来像这样。
8.035156 7.619141 7.105469
7.234375 7.8125 8.244141
6.615234 8.224609 6.361328
他们确实被“,”分开了。
输出应该看起来像这样
1:8.035156,2:7.619141,3:7.105469,4:7.072266
再次它应该被“,”分开。
但相反输出看起来像这样,甚至更奇怪,当我点击选择它给我时间。
01:08.0 02:07.6 03:07.1 04:07.1 05:07.4 06:07.2 07:07.6 08:07.1 09:07.1 10:07.2 12:04:06 AM
只有在append语句末尾添加了字符时才会输出错误的输出。
public class GeneCsv { public static void main(String[] args) throws IOException { File file = new File("file.csv"); FileWriter writer = new FileWriter("/Users/home/fileExpression.csv"); PrintWriter pw = new PrintWriter(writer); Scanner in = new Scanner(file); boolean firstLine = true; String[] temp = null; while (in.hasNextLine()) { if (firstLine == true) { pw.println(in.nextLine()); firstLine = false; continue; } else { String line = in.nextLine(); temp = line.split(","); for (int i = 0; i < temp.length; i++) { pw.append(i + ":" + temp[i] + ","); } pw.append("\n"); } } pw.flush(); pw.close(); writer.close(); } }
I'm getting weird output when I scan in a csv file split it by "," ,which for the length of each line I append the ith element with i + ":" to the printwriter.My original input looks something like this.
8.035156 7.619141 7.105469
7.234375 7.8125 8.244141
6.615234 8.224609 6.361328
which they are indeed seperated by ",".
The output should look something like this
1:8.035156,2:7.619141,3:7.105469,4:7.072266
again it should be seperated by ",".
but instead the output looks like this, even weirder when i click on the selection it gives me the time.
01:08.0 02:07.6 03:07.1 04:07.1 05:07.4 06:07.2 07:07.6 08:07.1 09:07.1 10:07.2 12:04:06 AM
The wrong output only happens when I add the
,
character at the end of the append statement.public class GeneCsv { public static void main(String[] args) throws IOException { File file = new File("file.csv"); FileWriter writer = new FileWriter("/Users/home/fileExpression.csv"); PrintWriter pw = new PrintWriter(writer); Scanner in = new Scanner(file); boolean firstLine = true; String[] temp = null; while (in.hasNextLine()) { if (firstLine == true) { pw.println(in.nextLine()); firstLine = false; continue; } else { String line = in.nextLine(); temp = line.split(","); for (int i = 0; i < temp.length; i++) { pw.append(i + ":" + temp[i] + ","); } pw.append("\n"); } } pw.flush(); pw.close(); writer.close(); } }
原文:https://stackoverflow.com/questions/10712936
最满意答案
像这样创建一个String资源:
<string name="wine_detail_header">Wine Details</string>
在values文件夹中的string.xml中。 然后你可以像这样使用它:
String s = myContext.getResources().getString(R.string.wine_detail_header);
Create a String resource like this:
<string name="wine_detail_header">Wine Details</string>
inside string.xml in values folder. You can then use it like this:
String s = myContext.getResources().getString(R.string.wine_detail_header);
相关问答
更多-
不,您不会遇到麻烦,但在xml中使用@string/yourString将是一种很好的做法, 它将使多语言支持更加容易。 No, you will not get into trouble, but using @string/yourString in your xml will be a good practice and it will make multi-language support easier.
-
Android Api 23更改导航视图headerLayout textview(Android Api 23 Change Navigation View headerLayout textview)[2022-12-23]
我有同样的问题,并能够避免使用这个代码: View header = LayoutInflater.from(this).inflate(R.layout.nav_header_main, null); navigationView.addHeaderView(header); TextView text = (TextView) header.findViewById(R.id.textView); text.setText("HELLO"); I had the sam ... -
使用这个android:layout_below="@+id/btnSend" 。将相对布局更改为线性Eclipse鼓励您使用strings.xml文件来声明字符串,而不是将它们硬编码到其他项目文件中,就像您正在做的那样。 strings.xml文件可以在项目的res/values/strings.xml中找到。 只需将字符串放在此文件中,如本例所示,并在其他项目文件中引用这些字符串。 以下是它的外观示例: new_layout.xml调用此方法correctAnswer(); 在将值设置为textview之前 public class MainActivity extends AppCompatActivity{ private boolean correct; private String questionTxt; public int correctAnswer() { int first = (int)(Math.random() * 10); int second = (int)(Math.random() * 10) ...
如何在android textview中显示API级别的硬编码字符串(How to display hardcoded string of API level in android textview)[2022-04-22]
像这样创建一个String资源:Wine Details 在values文件夹中的string.xml中。 然后你可以像这样使用它: String s = myContext.getResources().getString(R.string.wine_detail_header); Create a String resource like this:你对“微不足道”的主张基本上是真实的,但总的来说,“跳入深渊”很少导致溺水以外的其他事情。 我将成为“那个人”,并建议您在解决别人的API之前,实际上已经掌握了对Java的一般理解和最低限度的能力。 一旦你知道Java是如何工作的 - “PME”......属性,方法和事件 - 学习任何人的API都只是遵循正确步骤的问题。 除了PS的一点点,回答如下:1)从您的来源接收数据? 2)你在调用什么线程? 3)任何对象为空? 4)在查看控制台或日志时将引发任何异常(将日志与当前实现相比较)? 而且,不是无所事事, ...在API级别21之前使用带有android:drawableTop的矢量图像(Using vector images with android:drawableTop before API level 21)[2022-04-07]
没有办法将它与系统TextView一起使用。 (相关源代码: 5.1.1 / 4.4.4 ) 您可以使用自定义View类,但此时我认为您最好使用带有ImageView和TextView的LinearLayout。 There's no way to use it with the system TextView. (Relevant source code: 5.1.1 / 4.4.4) You could use a custom View class, but at this point I think ...删除this ,只需layout.addView(tv); 。 使用this仅用于引用实例变量。 (任何方法之外的类中的变量) Remove this, just layout.addView(tv);. Use this for referencing instance variables only. (Variables in the class outside of any methods)相关文章
更多- Real-Time Rendering 笔记 --- 1-4章
- javax.imageio.IIOException: Can't create output stream!的解决方案
- (五) solr 索引数据导入:csv格式
- The Log: What every software engineer should know about real-time data's unifying abstraction
- 用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空
- Java 流(Stream)、文件(File)和IO
- PHP 中dirname(_file_)
- 【HDFS】HADOOP DISTRIBUTED FILE SYSTEM
- xxx is not in the sudoers file解决方法
- shell 脚本执行,出现错误bad interpreter: No such file or directory
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)